var quickSearch = ""; // 快速查询
var btnAdvSearchflg = false; // 高级查询是否点击标识
var waitVerify; // 待审核
var waitAssign; // 待分派
var shipping; // 发货中
var shipped; // 已发货
var complete; // 已完成
var cancel; // 已废弃
var nEditing = null;
var deleteflg = false;
var stockImperfect; // 库存问题单
var goodsImperfect; // 商品问题单
var newOrderTable; // 创建订单Table
//var arrOrderGoodsId = new Array(); // 删除规格
var arrGoodsSku = new Array();// goodsSKu集合
var GoodsSkuMap = {};
var mapAdjustSku = {};
var searchCondition = { // 高级检索
    "tradeCode" : "", // 平台交易号
    "orderCode" : "", // 订单编号
    "shopId" : "", // 店铺
    "orderType" : "", // 来源
    "orderTimeS" : "", // 拍单时间 开始日期
    "paidDateS" : "", // 付款时间 开始日期
    "shipTimeS" : "", // 发货时间 开始日期
    "finishTimeS" : "", // 完成时间 开始日期
    "orderTimeE" : "", // 拍单时间 开始日期
    "paidDateE" : "", // 付款时间 开始日期
    "shipTimeE" : "", // 发货时间 开始日期
    "finishTimeE" : "", // 完成时间 开始日期
    "skuCode" : "", // 规格商家编码
    "buyerNick" : "", // 客户ID
    "ecItemCode" : "", // 平台商品编码
    "ecSkuCode" : "", // 平台规格编码
    "errorType" : "", // 错误类型
    
    "stamp":"",
    "customerService":"",
    "combStus":""
};
var selectStorTable;// 批量设置仓库的列表
var selectLgstTable;// 批量设置物流公司的列表
var shipOrderTable;// 分派画面中的表格
var nEditingshipOrder = null;
var orderSkuIndex = 0;
var emptyLgstCompany = "";// 生成发货单的时候需要确认信息，y是可以为空，n不可以为空，null或者空字符串忽略该检查(物流公司为空，是否确认分派？)
var hasrefund = "";// 生成发货单的时候需要确认信息，y是可以为空，n不可以为空，null或者空字符串忽略该检查(当前订单存在未废弃的退款单，是否确认分派？)
var orderIdAssign = "";//分派的时候传递OrderId
var frmNewOrderValidate = null;
var orderSkuRowIndex = 0;
var mapOrderSku = {};
var adjustTableUpdate= null;

//初始化iCheck组件
turn_on_iCheck = function(domElement) {
    return $('input[type="checkbox"],input[type="radio"]', domElement).iCheck({
        checkboxClass : 'icheckbox_flat-red',
        radioClass : 'iradio_flat-red'
    });
};
/**
 * 页面初期化
 */
$(document)
        .ready(
                function() {
                    $("#btnConfirm").hide();
                    //按钮控制
                    setPageElementStatus("orderList");
                    $("#frmOrderAssign").validate({
                    	 debug:true,
                        rules : {
                            consMobileAssign:{
                                consMobileAssignRule:true
                            }
                        },
                    	 errorPlacement: function(error, element)
                         {
                             error.insertAfter(element);
                         }
                    });
                    
                    frmNewOrderValidate = $("#frmNewOrder").validate({
                        debug:true,
                        groups: {
                    	    number: "consTelNew consMobileNew"
                    	  },
                        rules : {
                            /*consTelNew:{  
                            	consTelNewRule:true
                            },  
                            consMobileNew:{  
                            	consMobileNewRule:true
                            },*/
                        	consTelNew:{
                				required: {
                					depends:function(){
                						return (window.top.window.$('input[name=consMobileNew]').val().length <= 0);
                					}
                				}
                			},
                			consMobileNew:{
                				required: {
                					depends:function(){
                						return (window.top.window.$('input[name=consTelNew]').val().length <= 0);
                					}
                				}
                			},
                            lgstNoNew:{
                            	lgstNoNewRule:true
                            },
                            paidFeeNew:{
                            	paidFeeNewRule:true
                            },
                            lgstFeeNew:{
                            	lgstFeeNewRule:true
                            }
                        },
                        errorPlacement: function(error, element)
                        {
                            error.insertAfter(element);
                        },
                        messages:{ //提示报错  
                        	consTelNew:"固定电话和手机号码至少要输入一个。",  
                        	consMobileNew:"固定电话和手机号码至少要输入一个。"  
                        }, 
                    });
                 // 手机号码验证// 固话
                    $.validator.addMethod("consMobileNewRule", function(value, element) {
                        var rule = /^1[34578]\d{9}$/;
                        return this.optional(element) || (rule.test(value));
                    }, "您输入的手机号码有误！请重新输入正确手机号！");
                    $.validator.addMethod("consTelNewRule", function(value, element) {
                        var rule = /^((0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
                        return this.optional(element) || (rule.test(value));
                    }, "您输入的固定电话号码有误！请重新输入正确固定电话！");
                    // 初始化物流单号控件
                    $.validator.addMethod("lgstNoNewRule", function(value, element) {
                        var rule = /^[0-9a-zA-Z]*$/g ;;
                        return this.optional(element) || (rule.test(value));
                    }, "您输入的物流单号有误！请重新输入！");
                    //  
                    // 支付金额
                    $.validator.addMethod("paidFeeNewRule", function(value, element) {
                        var rule = /^([1-9]\d{0,9}|0)([.]?|(\.\d{1,2})?)$/;;
                        return this.optional(element) || (rule.test(value));
                    }, "您输入的金额有误！请重新输入！");
                    // 手机号 (手动分派)
                    $.validator.addMethod("consMobileAssignRule", function(value, element) {
                        var rule = /^\+?[0-9]\d*$/;;
                        return this.optional(element) || (rule.test(value));
                    }, "您输入的手机号有误！请重新输入！");

                 // 物流费用
                    $.validator.addMethod("lgstFeeNewRule", function(value, element) {
                        var rule = /^([1-9]\d{0,9}|0)([.]?|(\.\d{1,2})?)$/;;
                        return this.optional(element) || (rule.test(value));
                    }, "您输入的金额有误！请重新输入！");
                    $("#optionsRadios1").change(function() { 
                        if (window.top.window.$("#optionsRadios1").attr("checked")=="checked"){
                            window.top.window.$("#ecTradeCode").attr('readonly',false);
                            window.top.window.$("#buyerNickDownload").attr('readonly',true);
                            window.top.window.$("#optionsDiv1").html("<span class='require'>*</span>");
                            window.top.window.$("#optionsDiv2").html("");
                        } else {
                            window.top.window.$("#ecTradeCode").attr('readonly',true);
                            window.top.window.$("#buyerNickDownload").attr('readonly',false);
                            window.top.window.$("#optionsDiv2").html("<span class='require'>*</span>");
                            window.top.window.$("#optionsDiv1").html("");
                        }  
                    }); 
                    
                    $("#optionsRadios2").change(function() { 
                        if (window.top.window.$("#optionsRadios1").attr("checked")=="checked"){
                            window.top.window.$("#ecTradeCode").attr('readonly',false);
                            window.top.window.$("#buyerNickDownload").attr('readonly',true);
                            window.top.window.$("#optionsDiv1").html("<span class='require'>*</span>");
                            window.top.window.$("#optionsDiv2").html("");
                        } else {
                            window.top.window.$("#ecTradeCode").attr('readonly',true);
                            window.top.window.$("#buyerNickDownload").attr('readonly',false);
                            window.top.window.$("#optionsDiv2").html("<span class='require'>*</span>");
                            window.top.window.$("#optionsDiv1").html("");
                        }  
                    });

                    //导入画面的保存按钮
                    $("#btnAdjustAdd").click(function(){

                        // 画面传递参数的object
                        var orderInfoList = new Object();

                        var orderInfoVOs = new Array();

                        var orderInfo = new Object();
                        // order
                        var order = new Object();
                        // orderSku
                        var arrSku = new Array();
                        var flg = true;
                        var msg = "";

                        var shopTypeImport ="";
                        var tradeCodeImport = "";
                        window.top.window.$('#adjustTableUpdate tbody tr').each(function(index) {
                            var orderSku = new Object();
                            var aData = adjustTableUpdate.fnGetData(this);

                            if (shopTypeImport!=aData[1] || tradeCodeImport!=aData[2]){
                                if (index > 0){
                                    orderInfo.arrSku = arrSku;
                                    orderInfo.type = "all";
                                    orderInfoVOs.push(orderInfo);
                                }

                                orderInfo = new Object();
                                order = new Object();
                                arrSku = new Array();

                                // 整备order信息
                                order.shopType = aData[1];
                                order.orderType = "担保交易";
                                order.tradeCode = aData[2];
                                order.shopId = "";//后台搞定
                                order.shopName = aData[0];//只有在导入的时候，这个字段放的是shopAccount
                                order.buyerNick = aData[3];
                                order.storId = "";//后台搞定
                                order.storName = "";//后台搞定
                                order.storCode = aData[4];
                                order.payMode = "其他";
                                order.paidFee = aData[17];
                                order.paidDate = aData[18];
                                order.lgstId = "";//后台搞定
                                order.lgstName = "";//后台搞定
                                order.lgstCode = aData[5];
                                order.lgstNo = aData[6];
                                order.lgstFee = aData[19];
                                order.salesman = aData[7];
                                order.cons = aData[9];
                                order.consTel = aData[11];
                                order.consMobile = aData[10];
                                order.consAddr = aData[12];
                                order.consPostCode = aData[16];
                                order.provName = aData[13];
                                order.areaCoding = "";//后台搞定
                                order.cityName = aData[14];
                                order.distName = aData[15];
                                order.remark = aData[8];
                                orderInfo.order = order;
                                orderInfo.action = "insert";
                                orderSku.action = "insert";
                            }
                            shopTypeImport=aData[1];
                            tradeCodeImport=aData[2];
                            orderSku.goodsId = "";//后台搞定
                            orderSku.skuId = "";//后台搞定
                            orderSku.goodsCode = "";//后台搞定
                            orderSku.goodsName = "";//后台搞定
                            orderSku.skuCode = aData[20];
                            orderSku.skuName = "";//后台搞定
                            orderSku.qty = aData[21];

                            orderSku.isGift = "";//后台搞定
                            orderSku.isVirt = "";//后台搞定
                            orderSku.salePrice = "";//后台搞定
                            orderSku.factUnitPrice = aData[22];
                            orderSku.remark = aData[23];
                            arrSku.push(orderSku);
                        });
                        orderInfo.arrSku = arrSku;
                        orderInfo.type = "all";
                        orderInfoVOs.push(orderInfo);

                        orderInfoList.orderInfoVOs = orderInfoVOs;
                        orderInfoList.checkPrice = "y";
                        orderInfoList.checkCash = "y";
                        makeDataImport(orderInfoList, 'y', 'y'); //createOrderImport
                    });

                    function makeDataImport(orderInfoList, checkPrice, checkCash) {
                        // orderInfo.checkPrice = checkPrice;
                        // orderInfo.checkCash = checkCash;
                    	var loading = window.top.window.getIndexBusyOverlay();
                        $.ajax({
                            type : "POST",
                            url : "/order/createOrderImport.action",
                            data : JSON.stringify(orderInfoList),
                            contentType : "application/json;charset=utf-8",
                            dataType : "json",
                            beforeSend:function(){
                                if(loading) {
                                	loading.settext("正在处理中，请稍后...");
                                }
                            },
                            success : function(data) {
                            	loading.remove();
                            	window.top.window.returnCustomModalDialog();
                                if (data.success == "y") {
                                    $('#newAdjustPage').modal('hide');
                                    $("div .active").each(function() {
                                        switch ($(this).attr("id")) {
                                            case "waitVerifyTab": // 待审核
                                                waitVerify.draw();
                                                break;
                                            case "waitAssignTab": // 待分派
                                                waitAssign.draw();
                                                break;
                                            case "shippingTab": // 发货中
                                                shipping.draw();
                                                break;
                                            case "shippedTab": // 已发货
                                                shipped.draw();
                                                break;
                                            case "completeTab": // 已完成
                                                complete.draw();
                                                break;
                                            case "cancelTab": // 已废弃
                                                cancel.draw();
                                                break;
                                            default:
                                                break;
                                        }
                                    });
                                    window.top.window.showModalAlert('数据更新成功');
                                    // window.top.window.borrowCustomModalDialog($("#newAdjustPage"));
                                } else if (data.success == "q_Price") {
                                    var reg = new RegExp(/\\n/,"g");
                                    // var errormessage = data.errormessage.replace(reg, "<br/>");
                                    var r = confirm(data.errormessage.replace(reg, "\r"));
                                    if (r == true) {
                                        orderInfoList.checkPrice = "n";
                                    	makeDataImport(orderInfoList, "n", orderInfoList.checkCash);
                                    } else {
                                        var editDialog = window.top.window.borrowCustomModalDialog($("#newAdjustPage"));
                                        editDialog.modal({
                                            show : true,
                                            backdrop : 'static'
                                        });
                                    }
                                } else if (data.success == "q_cash") {
                                    var reg = new RegExp(/\\n/,"g");
                                    var r = confirm(data.errormessage.replace(reg, "\r"));
                                    if (r == true) {
                                        orderInfoList.checkCash = "n";
                                    	makeDataImport(orderInfoList, orderInfoList.checkPrice, "n");
                                    } else {
                                        var editDialog = window.top.window.borrowCustomModalDialog($("#newAdjustPage"));
                                        editDialog.modal({
                                            show : true,
                                            backdrop : 'static'
                                        });
                                    }
                                } else {
                                    var reg = new RegExp(/\\n/,"g")
                                    window.top.window.showModalAlertPretty(data.errormessage.replace(reg, "<br/>"));
                                    var editDialog = window.top.window.borrowCustomModalDialog($("#newAdjustPage"));
                                    editDialog.modal({
                                        show : true,
                                        backdrop : 'static'
                                    });
                                }

                            },
                            error : function(XMLHttpRequest, textStatus) {
                            	loading.remove();
                                if (XMLHttpRequest.status == 500) {
                                    var result = eval("(" + XMLHttpRequest.responseText + ")");
                                    alert(result.errorObject.errorText);
                                }
                            }
                        });
                    }

                    //手动下载
                    $("#btnDownLoad").click(function(){
                        //画面值
                        var downLoad = new Object();
                        downLoad.shopId = window.top.window.$("#shopIdDownLoad").val();
                        downLoad.shopType =  window.top.window.$("#shopIdDownLoad").find("option:selected").attr("shopType");
                        if (window.top.window.$("#optionsRadios1").attr("checked")=="checked"){
                            downLoad.choise = "t";
                            downLoad.ecTradeCode = window.top.window.$("#ecTradeCode").val();
                            downLoad.buyerNick = "";
                        } else {
                            downLoad.choise = "b";
                            downLoad.ecTradeCode = "";
                            downLoad.buyerNick = window.top.window.$("#buyerNickDownload").val();
                        }
                        
                        if (downLoad.shopType=="唯品会直发" && window.top.window.$("#optionsRadios2").attr("checked")=="checked") {
                        	window.top.window.showModalAlert("该平台对应的店铺不支持此下载功能");
                        	return;
                        }

                        if (downLoad.shopType=="网易考拉" && window.top.window.$("#optionsRadios2").attr("checked")=="checked") {
                            window.top.window.showModalAlert("该平台对应的店铺不支持此下载功能");
                            return;
                        }
                        
                        $.ajax({
                            type:"POST",
                            url:"/order/downLoadOrder.action",
                            data:JSON.stringify(downLoad),
                            contentType: "application/json;charset=utf-8",
                            dataType: "json",
                            async: false, // 同步
                            success:function(data) {
                                if (data.success == "y") {
//                                    window.top.window.showModalAlert("下载成功");
                                    window.top.window.showScoMessage("ok", "下载成功");
                                    $('#modalDownLoad', window.top.document).find("#btnDownLoadClose").click();
                                } else{
                                    window.top.window.showModalAlert(data.errormessage);
                                }
                                
                            },
                            error:function(XMLHttpRequest, textStatus) {
                                if (XMLHttpRequest.status == 500) {
                                    var result = eval("(" + XMLHttpRequest.responseText + ")");
                                    alert(result.errorObject.errorText);
                                }
                            }
                            });
                    }); 
                    
                    // 全选，全不选
                    $("#chkAlla").click(function() {
                        var checkboxes = document.getElementsByName('chkOrdera');
                        for (var i = 0; i < checkboxes.length; i++) {
                            var checkbox = checkboxes[i];
                            if (!$(this).get(0).checked) {
                                checkbox.checked = false;
                            } else {
                                checkbox.checked = true;
                            }
                        }
                        if ($("#chkAlla").is(":checked")) {
                        	$("#waitVerifyTable").find(".icheck").iCheck("check");
                        } else {
                        	$("#waitVerifyTable").find(".icheck").iCheck("uncheck");
                        }
                    });

                    // 全选，全不选
                    $("#chkAlli").click(function() {
                        var checkboxes = document.getElementsByName('chkOrderi');
                        for (var i = 0; i < checkboxes.length; i++) {
                            var checkbox = checkboxes[i];
                            if (!$(this).get(0).checked) {
                                checkbox.checked = false;
                            } else {
                                checkbox.checked = true;
                            }
                        }
                    });

                    // 全选，全不选
                    $("#chkAllk").click(function() {
                        var checkboxes = document.getElementsByName('chkOrderk');
                        for (var i = 0; i < checkboxes.length; i++) {
                            var checkbox = checkboxes[i];
                            if (!$(this).get(0).checked) {
                                checkbox.checked = false;
                            } else {
                                checkbox.checked = true;
                            }
                        }
                    });

                    // 全选，全不选
                    $("#chkAllr").click(function() {
                        var checkboxes = document.getElementsByName('chkOrderr');
                        for (var i = 0; i < checkboxes.length; i++) {
                            var checkbox = checkboxes[i];
                            if (!$(this).get(0).checked) {
                                checkbox.checked = false;
                            } else {
                                checkbox.checked = true;
                            }
                        }
                    });

                    // 全选，全不选
                    $("#chkAllz").click(function() {
                        var checkboxes = document.getElementsByName('chkOrderz');
                        for (var i = 0; i < checkboxes.length; i++) {
                            var checkbox = checkboxes[i];
                            if (!$(this).get(0).checked) {
                                checkbox.checked = false;
                            } else {
                                checkbox.checked = true;
                            }
                        }
                    });

                    // 全选，全不选
                    $("#chkAllcancel").click(function() {
                        var checkboxes = document.getElementsByName('chkOrdercancel');
                        for (var i = 0; i < checkboxes.length; i++) {
                            var checkbox = checkboxes[i];
                            if (!$(this).get(0).checked) {
                                checkbox.checked = false;
                            } else {
                                checkbox.checked = true;
                            }
                        }
                    });
                    
                 // 全选，全不选
                    $("#chkAllItem").click(function() {
                        var checkboxes = window.top.window.$("input:checkbox[name='chkPrjSku']");
                        for (var i = 0; i < checkboxes.length; i++) {
                            var checkbox = checkboxes[i];
                            if (!$(this).get(0).checked) {
                                checkbox.checked = false;
                            } else {
                                checkbox.checked = true;
                            }
                        }
                    });
                    
                    //清空按钮点击
                    $("#advSearchReset").click(function() {
                    	$("#hasInspected").val("");
                    	
                    	$("#frmAdvSearch .dropdown-menu ul").find("li").each(function(){
                    	    if ($(this).attr('class')=="selected"){
                    	        $(this).find("a")[0].click();    
                    	    }                    	    
                    	});
                    });

                    // 文字过长截断显示悬浮框
                    $("#waitVerifyTable").tooltip({
                        selector : ".tooltip-column-detail",
                        container : "body",
                        title : function() {
                            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                                return $(this).text();
                            }
                            if($(this).attr("class") == "fa fa-gear truncate-text tooltip-column-detail"){
                            	return "自动";
                            }
                            if($(this).attr("class") == "fa fa-thumbs-o-up truncate-text tooltip-column-detail"){
                            	return "手动";
                            }
                            if($(this).attr("class") == "fa fa-exclamation-circle truncate-text tooltip-column-detail"){
                            	return "问题";
                            }
                            if($(this).attr("class") == "fa fa-lock truncate-text tooltip-column-detail"){
                            	return "锁定";
                            }
                            if($(this).attr("class") == "badge badge-yellow truncate-text tooltip-column-detail"){
                                return "分派完成";
                            }
                            if($(this).attr("class") == "fa fa-phone truncate-text tooltip-column-detail"){
                            	return "售后";
                            }
                            if($(this).attr("class") == "fa fa-compress truncate-text tooltip-column-detail"){
                                return "合并";
                            }
                            if($(this).attr("class") == "fa fa-eye truncate-text tooltip-column-detail"){
                                return "验视";
                            }
                        }
                    });

                    // 文字过长截断显示悬浮框
                    $("#waitAssignTable").tooltip({
                        selector : ".tooltip-column-detail",
                        container : "body",
                        title : function() {
                            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                                return $(this).text();
                            }
                            if($(this).attr("class") == "fa fa-gear truncate-text tooltip-column-detail"){
                            	return "自动";
                            }
                            if($(this).attr("class") == "fa fa-thumbs-o-up truncate-text tooltip-column-detail"){
                            	return "手动";
                            }
                            if($(this).attr("class") == "fa fa-exclamation-circle truncate-text tooltip-column-detail"){
                            	return "问题";
                            }
                            if($(this).attr("class") == "fa fa-lock truncate-text tooltip-column-detail"){
                            	return "锁定";
                            }
                            if($(this).attr("class") == "badge badge-yellow truncate-text tooltip-column-detail"){
                                return "分派完成";
                            }
                            if($(this).attr("class") == "fa fa-phone truncate-text tooltip-column-detail"){
                            	return "售后";
                            }
                            if($(this).attr("class") == "fa fa-compress truncate-text tooltip-column-detail"){
                                return "合并";
                            }
                            if($(this).attr("class") == "fa fa-eye truncate-text tooltip-column-detail"){
                                return "验视";
                            }
                        }
                    });

                    // 文字过长截断显示悬浮框
                    $("#shippingTable").tooltip({
                        selector : ".tooltip-column-detail",
                        container : "body",
                        title : function() {
                            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                                return $(this).text();
                            }
                            if($(this).attr("class") == "fa fa-gear truncate-text tooltip-column-detail"){
                            	return "自动";
                            }
                            if($(this).attr("class") == "fa fa-thumbs-o-up truncate-text tooltip-column-detail"){
                            	return "手动";
                            }
                            if($(this).attr("class") == "fa fa-exclamation-circle truncate-text tooltip-column-detail"){
                            	return "问题";
                            }
                            if($(this).attr("class") == "fa fa-lock truncate-text tooltip-column-detail"){
                            	return "锁定";
                            }
                            if($(this).attr("class") == "badge badge-yellow truncate-text tooltip-column-detail"){
                                return "分派完成";
                            }
                            if($(this).attr("class") == "fa fa-phone truncate-text tooltip-column-detail"){
                            	return "售后";
                            }
                            if($(this).attr("class") == "fa fa-compress truncate-text tooltip-column-detail"){
                                return "合并";
                            }
                            if($(this).attr("class") == "fa fa-eye truncate-text tooltip-column-detail"){
                                return "验视";
                            }
                        }
                    });

                    // 文字过长截断显示悬浮框
                    $("#shippedTable").tooltip({
                        selector : ".tooltip-column-detail",
                        container : "body",
                        title : function() {
                            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                                return $(this).text();
                            }
                            if($(this).attr("class") == "fa fa-gear truncate-text tooltip-column-detail"){
                            	return "自动";
                            }
                            if($(this).attr("class") == "fa fa-thumbs-o-up truncate-text tooltip-column-detail"){
                            	return "手动";
                            }
                            if($(this).attr("class") == "fa fa-exclamation-circle truncate-text tooltip-column-detail"){
                            	return "问题";
                            }
                            if($(this).attr("class") == "fa fa-lock truncate-text tooltip-column-detail"){
                            	return "锁定";
                            }
                            if($(this).attr("class") == "badge badge-yellow truncate-text tooltip-column-detail"){
                                return "分派完成";
                            }
                            if($(this).attr("class") == "fa fa-phone truncate-text tooltip-column-detail"){
                            	return "售后";
                            }
                            if($(this).attr("class") == "fa fa-compress truncate-text tooltip-column-detail"){
                                return "合并";
                            }
                            if($(this).attr("class") == "fa fa-eye truncate-text tooltip-column-detail"){
                                return "验视";
                            }
                        }
                    });

                    // 文字过长截断显示悬浮框
                    $("#completeTable").tooltip({
                        selector : ".tooltip-column-detail",
                        container : "body",
                        title : function() {
                            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                                return $(this).text();
                            }
                            if($(this).attr("class") == "fa fa-gear truncate-text tooltip-column-detail"){
                            	return "自动";
                            }
                            if($(this).attr("class") == "fa fa-thumbs-o-up truncate-text tooltip-column-detail"){
                            	return "手动";
                            }
                            if($(this).attr("class") == "fa fa-exclamation-circle truncate-text tooltip-column-detail"){
                            	return "问题";
                            }
                            if($(this).attr("class") == "fa fa-lock truncate-text tooltip-column-detail"){
                            	return "锁定";
                            }
                            if($(this).attr("class") == "badge badge-yellow truncate-text tooltip-column-detail"){
                                return "分派完成";
                            }
                            if($(this).attr("class") == "fa fa-phone truncate-text tooltip-column-detail"){
                            	return "售后";
                            }
                            if($(this).attr("class") == "fa fa-compress truncate-text tooltip-column-detail"){
                                return "合并";
                            }
                            if($(this).attr("class") == "fa fa-eye truncate-text tooltip-column-detail"){
                                return "验视";
                            }
                        }
                    });
                    // 文字过长截断显示悬浮框
                    $("#cancelTable").tooltip({
                        selector : ".tooltip-column-detail",
                        container : "body",
                        title : function() {
                            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                                return $(this).text();
                            }
                            if($(this).attr("class") == "fa fa-gear truncate-text tooltip-column-detail"){
                            	return "自动";
                            }
                            if($(this).attr("class") == "fa fa-thumbs-o-up truncate-text tooltip-column-detail"){
                            	return "手动";
                            }
                            if($(this).attr("class") == "fa fa-exclamation-circle truncate-text tooltip-column-detail"){
                            	return "问题";
                            }
                            if($(this).attr("class") == "fa fa-lock truncate-text tooltip-column-detail"){
                            	return "锁定";
                            }
                            if($(this).attr("class") == "badge badge-yellow truncate-text tooltip-column-detail"){
                                return "分派完成";
                            }
                            if($(this).attr("class") == "fa fa-phone truncate-text tooltip-column-detail"){
                            	return "售后";
                            }
                            if($(this).attr("class") == "fa fa-compress truncate-text tooltip-column-detail"){
                                return "合并";
                            }
                            if($(this).attr("class") == "fa fa-eye truncate-text tooltip-column-detail"){
                                return "验视";
                            }
                        }
                    });
                   

                    // 高级检索初期化的时候隐藏
                    var fromOther = "n";
                    $("#advSearchPanel").hide();
                    if (window.top.window.$("#q_orderTradeCode").val() != "") {
                        $("#tradeCode").val(window.top.window.$("#q_orderTradeCode").val());
                        window.top.window.$("#q_orderTradeCode").val("");
                        fromOther = "y";
                    }
                    if (window.top.window.$("#orderCode").val() != "") {
                        $("#orderCode").val(window.top.window.$("#orderCode").val());
                        window.top.window.$("#orderCode").val("");
                        fromOther = "y";
                    }
                    searchCondition = { // 高级检索
                            "tradeCode" : $('#tradeCode').val(), // 平台交易号
                            "orderCode" : $("#orderCode").val(), // 订单编号
                            "shopId" : $('#hidshopId').val(), // 店铺
                            "orderType" : $('#hidorderType').val(), // 来源
                            "orderTimeS" : $('#hidorderTimeS').val(), // 拍单时间
                            // 开始日期
                            "paidDateS" : $('#hidpaidDateS').val(), // 付款时间 开始日期
                            "shipTimeS" : $('#hidshipTimeS').val(), // 发货时间 开始日期
                            "finishTimeS" : $('#hidfinishTimeS').val(), // 完成时间
                            // 开始日期
                            "orderTimeE" : $('#hidorderTimeE').val(), // 拍单时间
                            // 开始日期
                            "paidDateE" : $('#hidpaidDateE').val(), // 付款时间 开始日期
                            "shipTimeE" : $('#hidshipTimeE').val(), // 发货时间 开始日期
                            "finishTimeE" : $('#hidfinishTimeE').val(), // 完成时间
                            // 开始日期
                            "skuCode" : $('#hidskuCode').val(), // 规格商家编码
                            "buyerNick" : $('#hidbuyerNick').val(), // 客户ID
                            "ecItemCode" : $('#hidecItemCode').val(), // 平台商品编码
                            "ecSkuCode" : $('#hidecSkuCode').val(), // 平台规格编码
                            "errorType" : $('#hiderrorType').val(),
                        // 错误类型
                            "stamp":"",
                            "customerService":"",
                            "combStus":""
                        };
                    // 数字
                    var showTab = getCounts();
                    if (fromOther=="y"){
                        if ("showWaitVerifyTab" == showTab) {
                            $("#waitVerify").click();
                            showWaitVerifyTab();
                        } else if ("showWaitAssignTab" == showTab) {
                            $("#waitAssign").click();
                            showWaitAssignTab();
                        } else if ("showShippingTab" == showTab) {
                            $("#shipping").click();
                            showShippingTab();
                        } else if ("showShippedTab" == showTab) {
                            $("#shipped").click();
                            showShippedTab();
                        } else if ("showCompleteTab" == showTab) {
                            $("#complete").click();
                            showCompleteTab();
                        } else if ("showCancelTab" == showTab) {
                            $("#cancel").click();
                            showCancelTab();
                        } else {
                            showWaitVerifyTab();
                        }
                    } else {
                        // 默认待审核显示
                        showWaitVerifyTab();
                    }



                    $('.panel-default .datetimepicker-default').datetimepicker();
                    $(".selectpicker").selectpicker({
                        'noneSelectedText' : '请选择'
                    });
                    $(".selectpicker").selectpicker('refresh');
                    $(".panel-default .input-group-addon").hide();
                    // alert($(window.parent.document).find("#contentFrame1").attr("myid"));

                    // 设置店铺的下拉列表
                    setShopValue();

                    // 省 初期化
                    $.ajax({
                        type : "GET",
                        url : "/area/getProvList.action",
                        contentType : "application/json;charset=utf-8",
                        dataType : "json",
                        async : true,// 同步
                        success : function(data) {
                            if (data.result == "success") {
                                $("#provNameNew option").remove();
                                $("#provNameNew").append("<option value=''>请选择</option>");
                                $.each(data.data, function(n, value) {
                                    $('#provNameNew').append("<option value='" + value.areaCode + "'>" + value.areaName + "</option>");
                                });

                                $("#provNameAssign option").remove();
                                $("#provNameAssign").append("<option value=''>请选择</option>");
                                $.each(data.data, function(n, value) {
                                    $('#provNameAssign').append("<option value='" + value.areaCode + "'>" + value.areaName + "</option>");
                                });
                            } else {
                                window.top.window.showModalAlert(data.msg);
                            }
                        },
                        error : function(XMLHttpRequest, textStatus) {
                            if (XMLHttpRequest.status == 500) {
                                var result = eval("(" + XMLHttpRequest.responseText + ")");
                                alert(result.errorObject.errorText);
                            }
                        }
                    });

                    // 事件
                    // window.top.window.$("#projectSwitch").change(function() {
                    //     setShopValue();
                    // });

                    $("#btnAdvSearch").click(function() {
                        btnAdvSearchflg = true;
                        if ($("#advSearchPanel").is(":hidden")) {
                        	$("#btnQuickSearch").hide();
                            $("#advSearchPanel").show();
                            $(this).children("i:eq(0)").removeClass("fa-angle-double-down");
                            $(this).children("i:eq(0)").addClass("fa-angle-double-up");
                        } else {
                        	$("#advSearchPanel").hide();
                            $("#btnQuickSearch").show();
                            $(this).children("i:eq(0)").removeClass("fa-angle-double-up");
                            $(this).children("i:eq(0)").addClass("fa-angle-double-down");
                        }

                    });

//                    $("#advSearchPanel").click(function() {
//                        btnAdvSearchflg = true;
//                    })
//                    //邮编失去焦点校验
//                    $("#consPostCodeNew").blur(function(){
//                    	var code=window.top.window.$("#consPostCodeNew").val();
//                    	if(code != ""){
//                    		if(!is_code(code)){
//                    			window.top.window.showModalAlert("您的邮编输入有误！请重新输入");
//                    			window.top.window.$("#consPostCodeNew").val("");
//                    		}
//                    	}
//                    });
//                  //验证邮政编码  
//                    function is_code(code) {  
//                            if (! /^[0-9][0-9]{5}$/.test(code)) {  
//                                return false;  
//                            }  
//                        return true;  
//                    }
//                  //邮编失去焦点校验
//                    $("#consNew").blur(function(){
//                    	var name=window.top.window.$("#consNew").val();
//                        var myReg = /^[\u4e00-\u9fa5]+$/;
//                    	if(name != ""){
//                    		if (!myReg.test(name)) {
//                    			window.top.window.showModalAlert("您输入的收货人有误！请重新输入正确文本！");
//                    			window.top.window.$("#consNew").val("");
//                            }
//                    	}
//                    });
//                    //收货地址失去焦点校验
//                    $("#consAddrNew").blur(function(){
//                      var check = /^\d+$/;
//                      if(window.top.window.$("#consAddrNew").val()!=""){
//                    	  if(check.test(window.top.window.$("#consAddrNew").val())){
//                            	window.top.window.showModalAlert("您输入的收货地址为纯数字。");
//                            }
//                      }
//                    });
//
//                    //^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$
//                  //物流费用校验
//                    $("#lgstFeeNew").blur(function(){
//                      var check = /^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$/;
//                      if(window.top.window.$("#lgstFeeNew").val()!=""){
//                    	  if(!check.test(window.top.window.$("#lgstFeeNew").val())){
//                            	window.top.window.showModalAlert("请输入大于零，并且最多只有两位小数的值！");
//                            	window.top.window.$("#lgstFeeNew").val("");
//                            }
//                      }
//                    });
//                  //物流单号校验
//                    $("#lgstNoNew").blur(function(){
//                      var check =/^[0-9a-zA-Z]*$/g ;// /(?!^\d+$)(?!^[a-zA-Z]+$)[0-9a-zA-Z]{4,23}/;
//                      if(window.top.window.$("#lgstNoNew").val()!=""){
//                    	  if(!check.test(window.top.window.$("#lgstNoNew").val())){
//                            	window.top.window.showModalAlert("请正确输入物流单号！");
////                            	window.top.window.$("#lgstNoNew").val("");
//                            }
//                      }
//                    });
//                  //支付金额校验
//                    $("#paidFeeNew").blur(function(){
//                      var check =/^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$/;
//                      if(window.top.window.$("#paidFeeNew").val()!="" && window.top.window.$("#paidFeeNew").val()!="0" ){
//                    	  if(!check.test(window.top.window.$("#paidFeeNew").val())){
//                            	window.top.window.showModalAlert("请输入不小于零，并且最多只有两位小数的值！");
//                            	window.top.window.$("#paidFeeNew").val("");
//                            }
//                      }
//                    });

                    // /**
                    // * body点击的时候高级检索收回
                    // */
                    // $("body").click(function(e){
                    // if(btnAdvSearchflg==true){
                    // btnAdvSearchflg = false;
                    // } else {
                    // $("#advSearchPanel").hide();
                    // $("#btnAdvSearch").children("i:eq(0)").removeClass("fa-angle-double-up");
                    // $("#btnAdvSearch").children("i:eq(0)").addClass("fa-angle-double-down");
                    // }
                    // });

                    // 绑定事件
                    /**
                     * tab切换事件
                     */
                    $('a[data-toggle="tab"]').on('show.bs.tab', function(e) {

                        switch ($(this).attr("id")) {
                        case "waitVerify": // 待审核
                            showWaitVerifyTab();
                            break;
                        case "waitAssign": // 待分派
                            showWaitAssignTab();
                            break;
                        case "shipping": // 发货中
                            showShippingTab();
                            break;
                        case "shipped": // 已发货
                            showShippedTab();
                            break;
                        case "complete": // 已完成
                            showCompleteTab();
                            break;
                        case "cancel": // 已废弃
                            showCancelTab();
                            break;
                        default:
                            break;
                        }
                        getCounts();
                        
                    });

                    $('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
                        var tables = $.fn.dataTable.tables({
                            visible : true,
                            api : true
                        });
                        if (tables.length > 0) {
                            $(tables).DataTable().columns.adjust();
                        }
                        $(tables).find("th.sorting_asc").removeClass("sorting_asc");
                    });
                    
                    // 高级搜索“提交”按钮点击
                    $("#advSearchSubmit").click(function(e) {
                        // 记录高级查询的检索条件
                        setHidValue("frmAdvSearch");
                        var hasInspected = $('#hasInspected').val();
                        searchCondition = { // 高级检索
                            "tradeCode" : $('#hidtradeCode').val(), // 平台交易号
                            "orderCode" : $('#hidorderCode').val(), // 订单编号
                            "shopId" : $('#hidshopId').val(), // 店铺
                            "orderType" : $('#hidorderType').val(), // 来源
                            "orderTimeS" : $('#hidorderTimeS').val(), // 拍单时间
                            "hasInspected":hasInspected,
                            // 开始日期
                            "paidDateS" : $('#hidpaidDateS').val(), // 付款时间 开始日期
                            "shipTimeS" : $('#hidshipTimeS').val(), // 发货时间 开始日期
                            "finishTimeS" : $('#hidfinishTimeS').val(), // 完成时间
                            // 开始日期
                            "orderTimeE" : $('#hidorderTimeE').val(), // 拍单时间
                            // 开始日期
                            "paidDateE" : $('#hidpaidDateE').val(), // 付款时间 开始日期
                            "shipTimeE" : $('#hidshipTimeE').val(), // 发货时间 开始日期
                            "finishTimeE" : $('#hidfinishTimeE').val(), // 完成时间
                            // 开始日期
                            "skuCode" : $('#hidskuCode').val(), // 规格商家编码
                            "buyerNick" : $('#hidbuyerNick').val(), // 客户ID
                            "ecItemCode" : $('#hidecItemCode').val(), // 平台商品编码
                            "ecSkuCode" : $('#hidecSkuCode').val(), // 平台规格编码
                            "errorType" : $('#hiderrorType').val(),
                        // 错误类型
                            "stamp":$("#hidstamp").val(),
                            "customerService":$("#hidcustomerService").val(),
                            "combStus":$("#hidcombStus").val()
                        };
                        quickSearch = encodeURI($('#quickSearch').val());
                        $("div .active").each(function() {
                            switch ($(this).attr("id")) {
                            case "waitVerifyTab": // 待审核
                                showWaitVerifyTab();
                                break;
                            case "waitAssignTab": // 待分派
                                showWaitAssignTab();
                                break;
                            case "shippingTab": // 发货中
                                showShippingTab();
                                break;
                            case "shippedTab": // 已发货
                                showShippedTab();
                                break;
                            case "completeTab": // 已完成
                                showCompleteTab();
                                break;
                            case "cancelTab": // 已废弃
                                showCancelTab();
                                break;
                            default:
                                break;
                            }
                        });
                        getCounts();
                        // $("#advSearchPanel").hide();
                        // $("#btnAdvSearch").children("i:eq(0)").removeClass("fa-angle-double-up");
                        // $("#btnAdvSearch").children("i:eq(0)").addClass("fa-angle-double-down");

                    });
                    
                    /**
                     * 搜索框的回车事件
                     */ 
                    $('#quickSearch').keydown(function(e){
                        if(e.keyCode==13 && $('#btnQuickSearch').is(":visible")){
                            $("#btnQuickSearch").click();
                        }
                    });

                    /**
                     * 快速搜索，点击时提交表格刷新内容
                     */
                    $("#btnQuickSearch").click(function() {
                        quickSearch = encodeURI($('#quickSearch').val());
                        searchCondition = { // 高级检索
                            "tradeCode" : $('#hidtradeCode').val(), // 平台交易号
                            "orderCode" : $('#hidOrderCode').val(), // 订单编号
                            "shopId" : $('#hidshopId').val(), // 店铺
                            "orderType" : $('#hidorderType').val(), // 来源
                            "orderTimeS" : $('#hidorderTimeS').val(), // 拍单时间
                            // 开始日期
                            "paidDateS" : $('#hidpaidDateS').val(), // 付款时间 开始日期
                            "shipTimeS" : $('#hidshipTimeS').val(), // 发货时间 开始日期
                            "finishTimeS" : $('#hidfinishTimeS').val(), // 完成时间
                            // 开始日期
                            "orderTimeE" : $('#hidorderTimeE').val(), // 拍单时间
                            // 开始日期
                            "paidDateE" : $('#hidpaidDateE').val(), // 付款时间 开始日期
                            "shipTimeE" : $('#hidshipTimeE').val(), // 发货时间 开始日期
                            "finishTimeE" : $('#hidfinishTimeE').val(), // 完成时间
                            // 开始日期
                            "skuCode" : $('#hidskuCode').val(), // 规格商家编码
                            "buyerNick" : $('#hidbuyerNick').val(), // 客户ID
                            "ecItemCode" : $('#hidecItemCode').val(), // 平台商品编码
                            "ecSkuCode" : $('#hidecSkuCode').val(), // 平台规格编码
                            "errorType" : $('#hiderrorType').val(),
                        // 错误类型
                            "stamp":$("#hidstamp").val(),
                            "customerService":$("#hidcustomerService").val(),
                            "combStus":$("#hidcombStus").val()
                        };
                        searchCondition = {};//点击快速查询时清空高级查询项
                        $("div .active").each(function() {
                            switch ($(this).attr("id")) {
                            case "waitVerifyTab": // 待审核
                                showWaitVerifyTab();
                                break;
                            case "waitAssignTab": // 待分派
                                showWaitAssignTab();
                                break;
                            case "shippingTab": // 发货中
                                showShippingTab();
                                break;
                            case "shippedTab": // 已发货
                                showShippedTab();
                                break;
                            case "completeTab": // 已完成
                                showCompleteTab();
                                break;
                            case "cancelTab": // 已废弃
                                showCancelTab();
                                break;
                            default:
                                break;
                            }
                        });
                        getCounts();
                    });

                    // 高级查询中的时间类型变更的时候，开始时间，截止日期的控件赋值，显示，不显示
                    $("#dateType").bind("change", function() {
                        // if (this.value== "苹果")
                        switch (this.value) {
                        case "拍单时间": //
                            $("#startTime1").show();
                            $("#startTime2").hide();
                            $("#startTime3").hide();
                            $("#startTime4").hide();
                            $("#orderTimeS").val("");
                            $("#hidorderTimeS").val("");
                            $("#paidDateS").val("");
                            $("#hidpaidDateS").val("");
                            $("#shipTimeS").val("");
                            $("#hidshipTimeS").val("");
                            $("#finishTimeS").val("");
                            $("#hidfinishTimeS").val("");

                            $("#endTime1").show();
                            $("#endTime2").hide();
                            $("#endTime3").hide();
                            $("#endTime4").hide();
                            $("#orderTimeE").val("");
                            $("#hidorderTimeE").val("");
                            $("#paidDateE").val("");
                            $("#hidpaidDateE").val("");
                            $("#shipTimeE").val("");
                            $("#hidshipTimeE").val("");
                            $("#finishTimeE").val("");
                            $("#hidfinishTimeE").val("");
                            $(".input-group-addon").show();
                            break;
                        case "付款时间": //
                            $("#startTime1").hide();
                            $("#startTime2").show();
                            $("#startTime3").hide();
                            $("#startTime4").hide();
                            $("#orderTimeS").val("");
                            $("#hidorderTimeS").val("");
                            $("#paidDateS").val("");
                            $("#hidpaidDateS").val("");
                            $("#shipTimeS").val("");
                            $("#hidshipTimeS").val("");
                            $("#finishTimeS").val("");
                            $("#hidfinishTimeS").val("");

                            $("#endTime1").hide();
                            $("#endTime2").show();
                            $("#endTime3").hide();
                            $("#endTime4").hide();
                            $("#orderTimeE").val("");
                            $("#hidorderTimeE").val("");
                            $("#paidDateE").val("");
                            $("#hidpaidDateE").val("");
                            $("#shipTimeE").val("");
                            $("#hidshipTimeE").val("");
                            $("#finishTimeE").val("");
                            $("#hidfinishTimeE").val("");
                            $(".input-group-addon").show();
                            break;
                        case "发货时间": //
                            $("#startTime1").hide();
                            $("#startTime2").hide();
                            $("#startTime3").show();
                            $("#startTime4").hide();
                            $("#orderTimeS").val("");
                            $("#hidorderTimeS").val("");
                            $("#paidDateS").val("");
                            $("#hidpaidDateS").val("");
                            $("#shipTimeS").val("");
                            $("#hidshipTimeS").val("");
                            $("#finishTimeS").val("");
                            $("#hidfinishTimeS").val("");

                            $("#endTime1").hide();
                            $("#endTime2").hide();
                            $("#endTime3").show();
                            $("#endTime4").hide();
                            $("#orderTimeE").val("");
                            $("#hidorderTimeE").val("");
                            $("#paidDateE").val("");
                            $("#hidpaidDateE").val("");
                            $("#shipTimeE").val("");
                            $("#hidshipTimeE").val("");
                            $("#finishTimeE").val("");
                            $("#hidfinishTimeE").val("");
                            $(".input-group-addon").show();
                            break;
                        case "完成时间": //
                            $("#startTime1").hide();
                            $("#startTime2").hide();
                            $("#startTime3").hide();
                            $("#startTime4").show();
                            $("#orderTimeS").val("");
                            $("#hidorderTimeS").val("");
                            $("#paidDateS").val("");
                            $("#hidpaidDateS").val("");
                            $("#shipTimeS").val("");
                            $("#hidshipTimeS").val("");
                            $("#finishTimeS").val("");
                            $("#hidfinishTimeS").val("");

                            $("#endTime1").hide();
                            $("#endTime2").hide();
                            $("#endTime3").hide();
                            $("#endTime4").show();
                            $("#orderTimeE").val("");
                            $("#hidorderTimeE").val("");
                            $("#paidDateE").val("");
                            $("#hidpaidDateE").val("");
                            $("#shipTimeE").val("");
                            $("#hidshipTimeE").val("");
                            $("#finishTimeE").val("");
                            $("#hidfinishTimeE").val("");
                            $(".input-group-addon").show();
                            break;
                        default:
                            $("#orderTimeS").val("");
                            $("#hidorderTimeS").val("");
                            $("#paidDateS").val("");
                            $("#hidpaidDateS").val("");
                            $("#shipTimeS").val("");
                            $("#hidshipTimeS").val("");
                            $("#finishTimeS").val("");
                            $("#hidfinishTimeS").val("");
                            $("#orderTimeE").val("");
                            $("#hidorderTimeE").val("");
                            $("#paidDateE").val("");
                            $("#hidpaidDateE").val("");
                            $("#shipTimeE").val("");
                            $("#hidshipTimeE").val("");
                            $("#finishTimeE").val("");
                            $(".input-group-addon").hide();
                            break;
                        }
                    });

                    $(window).resize(function(){
                        var sonWidth = 0;
                        $("div .active").each(function() {
                            switch ($(this).attr("id")) {
                            case "waitVerifyTab": // 待审核
                                sonWidth = $("#widthWaitVerifyTab").width()-30;
                                $("#widthWaitVerifyTab iframe").each(function () {
                                    $(this).attr("width",sonWidth);
                                });
                                break;
                            case "waitAssignTab": // 待分派
                                sonWidth = $("#widthWaitAssignTab").width()-30;
                                $("#widthWaitAssignTab iframe").each(function () {
                                    $(this).attr("width",sonWidth);
                                });
                                // showWaitAssignTab();
                                break;
                            case "shippingTab": // 发货中
                                sonWidth = $("#widthShippingTab").width()-30;
                                $("#widthShippingTab iframe").each(function () {
                                    $(this).attr("width",sonWidth);
                                });
                                break;
                            case "shippedTab": // 已发货
                                sonWidth = $("#widthShippedTab").width()-30;
                                $("#widthShippedTab iframe").each(function () {
                                    $(this).attr("width",sonWidth);
                                });
                                break;
                            case "completeTab": // 已完成
                                sonWidth = $("#widthCompleteTab").width()-30;
                                $("#widthCompleteTab iframe").each(function () {
                                    $(this).attr("width",sonWidth);
                                });
                                break;
                            case "cancelTab": // 已废弃
                                sonWidth = $("#widthCancelTab").width()-30;
                                $("#widthCancelTab iframe").each(function () {
                                    $(this).attr("width",sonWidth);
                                });
                                break;
                            default:
                                break;
                            }
                        });
                        
                        
                    })
                    
                    // 子表格显示隐藏
                    $('.tablefirst tbody')
                            .on(
                                    'click',
                                    'td .fadu',
                                    function() {
                                        //宽度
                                        var sonWidth = 0;
                                        // 取得主键
                                        var orderId = $(this).attr('orderId');
                                        var shopType = $(this).attr('shopType');
                                        // var tab = $(this).attr('tabIndex');
                                        // 取得行
                                        var tr = $(this).closest('tr');
                                        var row;
                                        var table;
                                        var tablename = "";
                                        var tabIndex = "";
                                        // switch (tab) {
                                        // case "waitVerify": //待审核
                                        // table = waitVerify;
                                        // row = waitVerify.row(tr);
                                        // tablename = "waitVerifyTable";
                                        // tabIndex = "waitVerify";
                                        // break;
                                        // default:
                                        // break;
                                        // }
                                        $("div .active").each(function() {
                                            switch ($(this).attr("id")) {
                                            case "waitVerifyTab": // 待审核
                                                table = waitVerify;
                                                row = waitVerify.row(tr);
                                                tablename = "waitVerifyTable";
                                                tabIndex = "waitVerify";
                                                sonWidth = $("#widthWaitVerifyTab").width()-30;
                                                break;
                                            case "waitAssignTab": // 待分派
                                                table = waitAssign;
                                                row = waitAssign.row(tr);
                                                tablename = "waitAssignTable";
                                                tabIndex = "waitAssign";
                                                sonWidth = $("#widthWaitAssignTab").width()-30;
                                                break;
                                            case "shippingTab": // 发货中
                                                table = shipping;
                                                row = shipping.row(tr);
                                                tablename = "shippingTable";
                                                tabIndex = "shipping";
                                                sonWidth = $("#widthShippingTab").width()-30;
                                                break;
                                            case "shippedTab": // 已发货
                                                table = shipped;
                                                row = shipped.row(tr);
                                                tablename = "shippedTable";
                                                tabIndex = "shipped";
                                                sonWidth = $("#widthShippedTab").width()-30;
                                                break;
                                            case "completeTab": // 已完成
                                                table = complete;
                                                row = complete.row(tr);
                                                tablename = "completeTable";
                                                tabIndex = "complete";
                                                sonWidth = $("#widthCompleteTab").width()-30;
                                                break;
                                            case "cancelTab": // 已废弃
                                                table = cancel;
                                                row = cancel.row(tr);
                                                tablename = "cancelTable";
                                                tabIndex = "cancel";
                                                sonWidth = $("#widthCancelTab").width()-30;
                                                break;
                                            default:
                                                break;
                                            }
                                        });
                                        // 加载过，而且是显示的状态
                                        if (row.child.isShown()) {
                                            // This row is already open - close
                                            // it
                                            row.child.hide();
                                            tr.removeClass('shown');
                                            $(this).removeClass('fa-chevron-up');
                                            $(this).addClass('fa-chevron-down');
                                        } else {
                                            // 关闭其他
                                            $('#' + tablename + ' tbody tr').each(function() {
                                                if ($(this).attr("role") == "row") {
                                                    table.row($(this)).child.hide();
                                                }
                                            });
                                            $('.fa-chevron-up').addClass('fa-chevron-down');
                                            $('.fa-chevron-down').removeClass('fa-chevron-up');
                                            // 生成datatable的HTML代码
                                            // 判断相应的id的datatable是否存在
                                            if ($('#' + tablename + orderId + tabIndex).length <= 0) {
                                                var temp = '<iframe myid="'
                                                        + orderId
                                                        + ' tab="'
                                                        + tabIndex
                                                        + '" shopType="'
                                                        + shopType
                                                        + '" id="contentFrame1" name="contentFrame"  frameborder="0" src="/views/order/sonOrderList.html" width="'+sonWidth+'" height="400"></iframe>';
                                                // Open this row
                                                row.child(temp).show();
                                                tr.addClass('shown');
                                                $("#myid").val(orderId);
                                                $("#tab").val(tabIndex);
                                                $("#shopTypeHid").val(shopType);
                                            } else {
                                                tr.addClass('shown');
                                            }
                                            $(this).addClass('fa-chevron-up');
                                            $(this).removeClass('fa-chevron-down');
                                        }
                                        
                                    });

                    // 创建分单规则对话框关闭事件发生
                    $('#newOrderPage').on('hide.bs.modal', function() {
                        // 父窗体归还本页的编辑对话框
                        window.top.window.returnCustomModalDialog();
                    });
                    
                    $("#modalSysReturnDetail").on('hide.bs.modal', function() {
                        // 父窗体归还本页的编辑对话框
                        window.top.window.returnCustomModalDialog();
                    });

                 // 设置规则详情对话框关闭事件发生
                    $('#modalAddItem').on('hide.bs.modal', function () {
                        // 父窗体归还本页的编辑对话框
                        window.top.window.$("#frmSelPrjSku")[0].reset();
                        window.top.window.$('#addItemTable tbody').html("");
                        window.top.window.returnCustomModalDialog();
                        window.top.window.borrowCustomModalDialog($("#newOrderPage"));
                        
                    });
                    // 设置规则详情对话框关闭事件发生
                    $('#modalEditItem').on('hide.bs.modal', function () {
                        // 父窗体归还本页的编辑对话框
                        window.top.window.$("#frmSelPrjSku")[0].reset();
                        window.top.window.$('#addItemTable tbody').html("");
                        window.top.window.returnCustomModalDialog();
                        window.top.window.borrowCustomModalDialog($("#newOrderPage"));
                        
                    });
                    
                    /**
                     * 添加商品/添加赠品 中的重置按钮
                     */
                    $('#btnReset').on('click',function() {
                        $("#frmSelPrjSku")[0].reset();
                    });
                    
                    /**
                     * 添加商品/添加赠品 中的检索按钮
                     */
                    $('#btnPrjSkuSearch').on('click',function() {
                        doQuery("chk");
                    });
                    
                    var $modalEditItem = $("#modalEditItem");
                    
                    /**
                     * 修改商品 中的重置按钮
                     */
                    $('#btnReset',$modalEditItem).on('click',function() {
                        var $modalEditItem = $("#modalEditItem");
                        $("#frmSelPrjSku",$modalEditItem)[0].reset();
                    });
                    
                    /**
                     * 修改商品 中的检索按钮
                     */
                    $('#btnPrjSkuSearch',$modalEditItem).on('click',function() {
                        doQuery("radio");
                    });
                    
                    /**
                     * 添加商品/添加赠品画面的确定按钮
                     */
                    $("#btnAddItem").on('click',function(){
                        var prjSkuObj = new Object();
                        var skuCode = new Array();
                        if (window.top.window.$('input:checkbox[name=chkPrjSku]:checked').length<=0){
                            window.top.window.showModalAlert("请选择商品");
                            return false;
                        }
                        
                        window.top.window.$('input:checkbox[name=chkPrjSku]:checked').each(function(i) {
                            if(window.top.window.$('#isGift').val()=="n"){
                                if (mapOrderSku["n:"+$(this).attr("skuCode")]!=undefined){
                                    skuCode.push($(this).attr("skuCode"));
                                } 
                            } else {
                                if (mapOrderSku["y:"+$(this).attr("skuCode")]!=undefined){
                                    skuCode.push($(this).attr("skuCode"));
                                } 
                            }
                        });
                        
                        if (skuCode.length>0){
                            window.top.window.showModalAlert("规格编码："+skuCode.join(",")+"的数据已经存在，不能选择");                            
                            return false;
                        }
                        
                        window.top.window.$('input:checkbox[name=chkPrjSku]:checked').each(function(i) {
                            prjSkuObj.prjSkuId = $(this).attr("prjSkuId");
                            prjSkuObj.isGifts = $(this).attr("isGifts");
                            prjSkuObj.goodsId = $(this).attr("goodsId");
                            prjSkuObj.goodsCode = $(this).attr("goodsCode");
                            prjSkuObj.goodsName = $(this).attr("goodsName");
                            prjSkuObj.skuId = $(this).attr("skuId");
                            prjSkuObj.skuCode = $(this).attr("skuCode");
                            prjSkuObj.skuName = $(this).attr("skuName");
                            prjSkuObj.salePrice = $(this).attr("salePrice");   
                            
                            newOrderTable.fnAddData([ prjSkuObj.isGifts, prjSkuObj.goodsCode, prjSkuObj.goodsName, prjSkuObj.skuCode, prjSkuObj.skuName, '', prjSkuObj.salePrice, '', '', '', '', '',
                                '<a href="javascript:;" class="delete" orderGoodsId="">删除</a>' ]);
                            var value = new Object();
                            value.goodsId = prjSkuObj.goodsId;
                            value.skuId = prjSkuObj.skuId;
                            GoodsSkuMap[orderSkuRowIndex] = value;
                            orderSkuRowIndex++
                            
                            if(window.top.window.$('#isGift').val()=="n"){
                                mapOrderSku["n:"+$(this).attr("skuCode")]=$(this).attr("skuCode");
                            } else {
                                mapOrderSku["y:"+$(this).attr("skuCode")]=$(this).attr("skuCode");
                            }
                        });
                        window.top.window.$("#btnAddItemClose").click();
                    });
                    
                    /**
                     * 修改商品画面的确定按钮
                     */
                    $("#btnAddItem",$modalEditItem).on('click',function(e){
                        e.preventDefault();
                        var prjSkuObj = new Object();
                        var skuCode = new Array();
                        var selectSku = window.top.window.$('input:radio[name=chkPrjSku]:checked');
                        
                        if (selectSku.length<=0){
                            window.top.window.showModalAlert("请选择商品");
                            return false;
                        }
                        
                        var n = window.top.window.currentRowIndex;
                        var currentTable = window.top.window.currentOrderTable;
                        var currentData = window.top.window.currentRowData
                        
                        var notAllowedItem = window.top.window.$("#noAllowedSkuCode").val();
                        var notAllowedItemArray = notAllowedItem.split(",");
                        
                        for(var i=0,j=notAllowedItemArray.length;i<j;i++){
                            if($(selectSku).attr("skuCode")==notAllowedItemArray[i]){
                                window.top.window.showModalAlert("该商品已经存在，不能继续添加");
                                return;
                            }
                        }
                        
                        
                        prjSkuObj.prjSkuId = $(selectSku).attr("prjSkuId");
                        prjSkuObj.isGifts = $(selectSku).attr("isGifts");
                        prjSkuObj.goodsId = $(selectSku).attr("goodsId");
                        prjSkuObj.goodsCode = $(selectSku).attr("goodsCode");
                        prjSkuObj.goodsName = $(selectSku).attr("goodsName");
                        prjSkuObj.skuId = $(selectSku).attr("skuId");
                        prjSkuObj.skuCode = $(selectSku).attr("skuCode");
                        prjSkuObj.skuName = $(selectSku).attr("skuName");
                        
                        prjSkuObj.salePrice = $(selectSku).attr("salePrice");  
                        prjSkuObj.goodsSkuCost = $(selectSku).attr("goodsSkuCost");  
                        prjSkuObj.saleCount = prjSkuObj.salePrice*currentData[5];   
                        prjSkuObj.saleDiscount = (prjSkuObj.salePrice - currentData[8])>0?(prjSkuObj.salePrice - currentData[8]):"0";
                        
//                        orderTableUpdate.fnUpdate(prjSkuObj.goodsId,n,,false);
                        currentTable.fnUpdate(prjSkuObj.goodsCode,n,1,false);
                        currentTable.fnUpdate(prjSkuObj.goodsName,n,2,false);
//                        orderTableUpdate.fnUpdate(prjSkuObj.skuId,n,,false);
                        currentTable.fnUpdate(prjSkuObj.skuCode,n,3,false);
                        currentTable.fnUpdate(prjSkuObj.skuName,n,4,false);
                        currentTable.fnUpdate(prjSkuObj.salePrice,n,6,false);
                        
                        var tradeStatus = window.top.window.$("#tradeStatus").val();
                        if(!tradeStatus){
                            // 如果订单是手动创建，更新实际支付单价为实际单价；更新实际支付金额为实际金额
//                            currentTable.fnUpdate(prjSkuObj.salePrice,n,8,false);
//                            currentTable.fnUpdate(prjSkuObj.saleCount,n,10,false);
                        }

                        // 需要同步更新折扣信息
                        currentTable.fnUpdate(prjSkuObj.saleDiscount,n,7,false);
                        
                        currentTable.fnUpdate(prjSkuObj.saleCount,n,9,false);
                        
                        
                        $("#newOrderTable").find("tr").each(function () {
                            for(var i=0;i<20;i++){
                                $(this).children('td:eq('+i+')').attr("title", $(this).children('td:eq('+i+')').text());
                            }                      
                        });
                        
                        GoodsSkuMap[n].goodsId = prjSkuObj.goodsId;
                        GoodsSkuMap[n].skuId = prjSkuObj.skuId;
                        
                        GoodsSkuMap[n].goodsCode = prjSkuObj.goodsCode;
                        GoodsSkuMap[n].goodsName = prjSkuObj.goodsName;
                        GoodsSkuMap[n].skuCode = prjSkuObj.skuCode;
                        GoodsSkuMap[n].skuName = prjSkuObj.skuName;
                        GoodsSkuMap[n].salePrice = prjSkuObj.salePrice;
                        
                        // 需要同步保存成本价
                        GoodsSkuMap[n].goodsSkuCost = prjSkuObj.goodsSkuCost;
                            
                        window.top.window.$("#btnAddItemClose").click();
                    });
                    /**
                     * 添加商品
                     */
                    $('#createOrderGoods').on(
                            'click',
                            function() {
                                var modalAdd = $("#modalAddItem");
                                var orderStatus = $(this).parents("#newOrderPage").eq(0).find("#orderStatus").val();
                                var tradeStatus = $(this).parents("#newOrderPage").eq(0).find("#tradeStatus").val();
                                if(!!tradeStatus&&!!orderStatus&&orderStatus=="waitVerify"){
                                    // 交易号存在表示订单是自动生成的，同时订单状态是待审核，则不能添加系统商品
                                    window.top.window.showModalAlert("该订单是自动生成的，不能添加商品");
                                    return;
                                }
                                
                                $("#isGift",modalAdd).val("n");
                                $("#modalAddItemTitle",modalAdd).html("添加商品");

                                $("#chkAllItem",modalAdd).removeAttr("checked");
                                $('#skuGoodsCode',modalAdd).val("");
                                $('#skuGoodsName',modalAdd).val("");
                                $('#skuSkuCode',modalAdd).val("");
                                $('#skuSkuName',modalAdd).val("");

                                window.top.window.returnCustomModalDialog();
                                var editDialog = window.top.window.borrowCustomModalDialog($("#modalAddItem"));
                                editDialog.modal({show:true, backdrop:'static'});
//                                newOrderTable.fnAddData([ '', '', '', '', '', '', '', '', '', '', '', '',
//                                        '<a href="javascript:;" class="delete" orderGoodsId="">删除</a>' ]);
//                                newOrderTable.fnDraw();
                            });
                    /**
                     * 添加赠品
                     */
                    $('#createOrderGoodsGift').on(
                            'click',
                            function() {
                                var modalAdd = $("#modalAddItem");
                                $("#isGift",modalAdd).val("y");
                                $("#modalAddItemTitle",modalAdd).html("添加赠品");

                                $("#chkAllItem",modalAdd).removeAttr("checked");
                                $('#skuGoodsCode',modalAdd).val("");
                                $('#skuGoodsName',modalAdd).val("");
                                $('#skuSkuCode',modalAdd).val("");
                                $('#skuSkuName',modalAdd).val("");

                                window.top.window.returnCustomModalDialog();
                                var editDialog = window.top.window.borrowCustomModalDialog($("#modalAddItem"));
                                editDialog.modal({show:true, backdrop:'static'});
//                                newOrderTable.fnAddData([ '赠', '', '', '', '', '', '', '', '', '', '', '',
//                                        '<a href="javascript:;" class="delete" orderGoodsId="">删除</a>' ]);
//                                newOrderTable.fnDraw();
                            });

                    $('#newOrderPage').on('shown.bs.modal', function() {
//                        newOrderTable.fnDraw();
//                        $("#newForm").validate().clear();
                    	setInputSelectTitle();
                    });
                    
                    /**
                     * 省变化的时候，市，区的值要变化
                     */
                    $('#provNameNew').on(
                            'change',
                            function() {

                                if (window.top.window.$("#provNameNew").val() == "") {
                                    window.top.window.$("#cityNameNew").val("");
                                    window.top.window.$("#distNameNew").val("");
                                }

                                // 市 初期化
                                $.ajax({
                                    type : "GET",
                                    url : "/area/getCityList.action?provId=" + window.top.window.$("#provNameNew").val(),
                                    contentType : "application/json;charset=utf-8",
                                    dataType : "json",
                                    async : false,// 同步
                                    success : function(data) {
                                        if (data.result == "success") {
                                            window.top.window.$("#cityNameNew option").remove();
                                            window.top.window.$("#cityNameNew").append("<option value=''>请选择</option>");
                                            window.top.window.$("#distNameNew option").remove();
                                            window.top.window.$("#distNameNew").append("<option value=''>请选择</option>");
                                            $.each(data.data, function(n, value) {
                                                window.top.window.$('#cityNameNew').append(
                                                        "<option value='" + value.areaCode + "'>" + value.areaName + "</option>");
                                            });
                                        } else {
                                            window.top.window.showModalAlert(data.msg);
                                        }
                                    },
                                    error : function(XMLHttpRequest, textStatus) {
                                        if (XMLHttpRequest.status == 500) {
                                            var result = eval("(" + XMLHttpRequest.responseText + ")");
                                            alert(result.errorObject.errorText);
                                        }
                                    }
                                });
                            });

                    /**
                     * 省变化的时候，市，区的值要变化
                     */
                    $('#cityNameNew').on(
                            'change',
                            function() {

                                if (window.top.window.$("#cityNameNew").val() == "") {
                                    window.top.window.$("#distNameNew").val("");
                                }

                                // 区 初期化
                                $.ajax({
                                    type : "GET",
                                    url : "/area/getDistList.action?cityId=" + window.top.window.$("#cityNameNew").val(),
                                    contentType : "application/json;charset=utf-8",
                                    dataType : "json",
                                    async : false,// 同步
                                    success : function(data) {
                                        if (data.result == "success") {
                                            window.top.window.$("#distNameNew option").remove();
                                            window.top.window.$("#distNameNew").append("<option value=''>请选择</option>");
                                            $.each(data.data, function(n, value) {
                                                window.top.window.$('#distNameNew').append(
                                                        "<option value='" + value.areaCode + "'>" + value.areaName + "</option>");
                                            });
                                        } else {
                                            window.top.window.showModalAlert(data.msg);
                                        }
                                    },
                                    error : function(XMLHttpRequest, textStatus) {
                                        if (XMLHttpRequest.status == 500) {
                                            var result = eval("(" + XMLHttpRequest.responseText + ")");
                                            alert(result.errorObject.errorText);
                                        }
                                    }
                                });
                            });

                    /**
                     * 省变化的时候，市，区的值要变化
                     */
                    $('#provNameAssign').on(
                            'change',
                            function() {

                                if (window.top.window.$("#provNameAssign").val() == "") {
                                    window.top.window.$("#cityNameAssign").val("");
                                    window.top.window.$("#distNameAssign").val("");
                                }

                                // 市 初期化
                                $.ajax({
                                    type : "GET",
                                    url : "/area/getCityList.action?provId=" + window.top.window.$("#provNameAssign").val(),
                                    contentType : "application/json;charset=utf-8",
                                    dataType : "json",
                                    async : false,// 同步
                                    success : function(data) {
                                        if (data.result == "success") {
                                            window.top.window.$("#cityNameAssign option").remove();
                                            window.top.window.$("#cityNameAssign").append("<option value=''>请选择</option>");
                                            window.top.window.$("#distNameAssign option").remove();
                                            window.top.window.$("#distNameAssign").append("<option value=''>请选择</option>");
                                            $.each(data.data, function(n, value) {
                                                window.top.window.$('#cityNameAssign').append(
                                                        "<option value='" + value.areaCode + "'>" + value.areaName + "</option>");
                                            });
                                        } else {
                                            window.top.window.showModalAlert(data.msg);
                                        }
                                    },
                                    error : function(XMLHttpRequest, textStatus) {
                                        if (XMLHttpRequest.status == 500) {
                                            var result = eval("(" + XMLHttpRequest.responseText + ")");
                                            alert(result.errorObject.errorText);
                                        }
                                    }
                                });
                            });

                    /**
                     * 省变化的时候，市，区的值要变化
                     */
                    $('#cityNameAssign').on(
                            'change',
                            function() {

                                if (window.top.window.$("#cityNameAssign").val() == "") {
                                    window.top.window.$("#distNameAssign").val("");
                                }

                                // 区 初期化
                                $.ajax({
                                    type : "GET",
                                    url : "/area/getDistList.action?cityId=" + window.top.window.$("#cityNameAssign").val(),
                                    contentType : "application/json;charset=utf-8",
                                    dataType : "json",
                                    async : false,// 同步
                                    success : function(data) {
                                        if (data.result == "success") {
                                            window.top.window.$("#distNameAssign option").remove();
                                            window.top.window.$("#distNameAssign").append("<option value=''>请选择</option>");
                                            $.each(data.data, function(n, value) {
                                                window.top.window.$('#distNameAssign').append(
                                                        "<option value='" + value.areaCode + "'>" + value.areaName + "</option>");
                                            });
                                        } else {
                                            window.top.window.showModalAlert(data.msg);
                                        }
                                    },
                                    error : function(XMLHttpRequest, textStatus) {
                                        if (XMLHttpRequest.status == 500) {
                                            var result = eval("(" + XMLHttpRequest.responseText + ")");
                                            alert(result.errorObject.errorText);
                                        }
                                    }
                                });
                            });

                    /**
                     * 网店变化的时候，发货仓库的值要变化
                     */
                    $('#shopIdNew').on(
                            'change',
                            function() {

                                if (window.top.window.$("#shopIdNew").val() == "") {
                                    window.top.window.$("#storIdNew").val("");
                                    window.top.window.$("#storIdNew option").remove();
                                    window.top.window.$("#storIdNew").append("<option value=''>请选择</option>");
                                    return;
                                }

                                // 市 初期化
                                $.ajax({
                                    type : "GET",
                                    url : "/stor/getStorageByShopIdNoDelete.action?shopId=" + window.top.window.$("#shopIdNew").val(),
                                    contentType : "application/json;charset=utf-8",
                                    dataType : "json",
                                    async : false,// 同步
                                    success : function(data) {
                                        if (data.result == "success") {
                                            window.top.window.$("#storIdNew option").remove();
                                            window.top.window.$("#storIdNew").append("<option value=''>请选择</option>");
                                            $.each(data.data, function(n, value) {
                                                window.top.window.$('#storIdNew').append(
                                                        "<option value='" + value.storId + "'>" + value.storName + "</option>");
                                            });
                                        } else {
                                            window.top.window.showModalAlert(data.msg);
                                        }
                                    },
                                    error : function(XMLHttpRequest, textStatus) {
                                        if (XMLHttpRequest.status == 500) {
                                            var result = eval("(" + XMLHttpRequest.responseText + ")");
                                            alert(result.errorObject.errorText);
                                        }
                                    }
                                });
                            });

                    $("#confirmOK").on('click', function() {
                        $("#stack2").hide();
                    });
                    //
                    $('#newOrderTable').on('click', 'td', function(e) {
                        if (deleteflg == true) {
                            deleteflg = false;
                            return;
                        }
                        //alert($(this).context.cellIndex);
                        deleteflg = false;
                        // e.preventDefault();
                        var nRow = $(this).parents('tr')[0];
                        if (nEditing !== null && nEditing != nRow) {
                            saveRow(newOrderTable, nEditing);
                            editRow(newOrderTable, nRow);
                            nEditing = nRow;
                        } else {
                            var text = $(this).parent().find("input");
                            if (text.length <= 0) {
                                editRow(newOrderTable, nRow);
                            }
                            nEditing = nRow;
                        }
                    });
                    
                    
                    /*
                     * 点击恢复按钮时，恢复显示删除按钮和编辑按钮
                     */
                    $('#newOrderTable').on('click', 'a.back', function(e) {
                        deleteflg = true;
                        e.preventDefault();
                        var rowData = null;
                        var nRow = $(this).parents('tr')[0];
                        rowData = newOrderTable.fnGetData(nRow);
                        if (nEditing !== null && nEditing != nRow) {
                            saveRow(newOrderTable, nEditing);
                        }
                        
                        var deleteBtnString = '<a href="javascript:;" class="deleteU" orderskuid="'+$(this).attr("orderSkuId")+'">删除</a>';
                        var modifyBtnString = "";
                        if (!!rowData&&rowData.length>0&&"赠" != rowData[0]){
                            modifyBtnString = '<a href="javascript:;" class="modifyU" orderskuid="'+$(this).attr("orderSkuId")+'">修改</a>';
                        }
                        newOrderTable.fnUpdate(deleteBtnString+"&nbsp;"+modifyBtnString, nRow, 12, false);
                        nEditing = null;
                    });
                    
                    /*
                     * 点击商品的修改按钮，弹出商品选择页面并执行修改操作
                     */
                    $('#newOrderTable').on('click', 'a.modifyU', function(e) {
                        var nRow = $(this).parents('tr')[0];
                        // 在打开商品选择页面时，需要把当前table对象和row对象传递给新页面，这样才能在新页面上执行表格的更新操作
                        
                        var tableObj = newOrderTable;
                        var rowData = newOrderTable.fnGetData(nRow);
                        var rowObj = newOrderTable.fnGetNodes($(nRow).index());
                        
                        var noAllowedSkuCode = $(this).parents("#newOrderTable").find("tr:not(:eq(0))").find("td:eq(3)").map(function(){
                            return $(this).text();
                        }).get().join();
                        
                        window.top.window.currentOrderTable = tableObj;
                        window.top.window.currentRowData = rowData;
                        window.top.window.currentRowIndex = $(nRow).index();
                        
                        var $modalEditItem = $("#modalEditItem");
                        var orderStatus = $(this).parents("#newOrderPage").eq(0).find("#orderStatus").val();
                        var tradeCode = $(this).parents("#newOrderPage").eq(0).find("#tradeCodeNew").val();
                        $("#isGift",$modalEditItem).val("");
                        
                        if(rowData[0].indexOf('销')>=0){
                            $("#isVirt",$modalEditItem).val('n');
                        }else{
                            $("#isVirt",$modalEditItem).val('y');
                        }
                        $("#modalAddItemTitle",$modalEditItem).html("修改商品");

                        $("#chkAllItem",$modalEditItem).removeAttr("checked");
                        $('#skuGoodsCode',$modalEditItem).val("");
                        $('#skuGoodsName',$modalEditItem).val("");
                        $('#skuSkuCode',$modalEditItem).val("");
                        $('#skuSkuName',$modalEditItem).val("");
                        $('#noAllowedSkuCode',$modalEditItem).val(noAllowedSkuCode);

                        window.top.window.returnCustomModalDialog();
                        var editDialog = window.top.window.borrowCustomModalDialog($modalEditItem);
                        editDialog.modal({show:true, backdrop:'static'});
                    });
                    
                    /**
                     * 要变成恢复的删除按钮
                     */
                    $('#newOrderTable').on('click', 'a.deleteU', function(e) {
                        deleteflg = true;
                        e.preventDefault();
                        var nRow = $(this).parents('tr')[0];
                        if (nEditing !== null && nEditing != nRow) {
                            saveRow(newOrderTable, nEditing);
                        }
                        newOrderTable.fnUpdate('<a href="javascript:;" class="back" orderskuid="'+$(this).attr("orderSkuId")+'"><font style="color:red">恢复</font></a>', nRow, 12, false);
                        nEditing = null;
//                        if (nEditing !== null && nEditing != nRow) {
//                            saveRow(orderTableUpdate, nEditing);
//                        }
//                      var n = $(this).attr("rowIndex");
//                      var orderSkuId = $(this).attr("orderSkuId");
//                      var tab = $('#tab', window.parent.document).val();
//                      if ("waitVerify"!=tab){
//                          orderTableUpdate.fnUpdate('已删除', n, 19, false);
//                      } else {
//                          orderTableUpdate.fnUpdate('<a href="javascript:;" class="back" orderSkuId="'+orderSkuId+'" rowIndex ="'+n+'"><font style="color:red">恢复</font></a>', n, 19, false);    
//                      }
//                      nEditing = null;
                        
//                        var nRow = $(this).parents('tr')[0];
//                        window.top.window.$("#modalConfirmContent").text("要删除该行吗?");
//                        window.top.window.$('#btnModalOK').unbind();
//                        window.top.window.$("#btnModalOK").on('click', '', {
//                            nRow : nRow,
//                            orderGoodsId : $(this).attr("orderGoodsId")
//                        }, delOrderGoods);
//                        window.top.window.$('#modal-confirm').modal({
//                            show : true,
//                            backdrop : 'static'
//                        });
                    });

                    /**
                     * 要删除行的删除按钮
                     */
                    $('#newOrderTable').on('click', 'a.delete', function(e) {
                        deleteflg = true;
                        e.preventDefault();
                        var nRow = $(this).parents('tr')[0];
                        window.top.window.$("#modalConfirmContent").text("要删除该行吗?");
                        window.top.window.$('#btnModalOK').unbind();
                        window.top.window.$("#btnModalOK").on('click', '', {
                            nRow : nRow,
                            orderGoodsId : $(this).attr("orderGoodsId")
                        }, delOrderGoods);
                        window.top.window.$('#modal-confirm').modal({
                            show : true,
                            backdrop : 'static'
                        });
                    });
                    
                    $("#deleteAllOrderGoods").click(function() {
                        // window.top.window.showModalConfirmHtml(
                        // "删除项目将一并删除项目所有店铺，是否确认删除？", doAllDelete);
                        window.top.window.$("#modalConfirmContent").text("要删除所有行吗?");
                        window.top.window.$('#btnModalOK').unbind();
                        window.top.window.$("#btnModalOK").on('click', '', '', doAllDelete);
                        window.top.window.$('#modal-confirm').modal({
                            show : true,
                            backdrop : 'static'
                        });
                        nEditing = null;
                    });
                    // 创建保存按钮点击事件绑定
                    $("#btnOrderAdd").click(
                            function() {
                                // 画面传递参数的object
                                var orderInfo = new Object();
                                // order
                                var order = new Object();
                                // orderSku
                                var arrSku = new Array();
                                // var orderSku = new Object();
                                var flg = true;
                                var msg = "";
                                // if (!checkOrder()){
                                // return;
                                // }
                                //   
                                if(!$('#newOrderPage',window.top.document).find("#frmNewOrder").valid()) {
//                                	$("#btnOrderCancel").click();
                                    return;
                                }
                                // 整备order信息
                                order.shopType = window.top.window.$("#shopTypeNew").val();
                                order.orderType = window.top.window.$("#orderTypeNew").val();
                                order.tradeCode = window.top.window.$("#tradeCodeNew").val();
                                order.tradeStatus = window.top.window.$("#tradeStatus").val();
                                
                                order.shopId = window.top.window.$("#shopIdNew").val();
                                order.shopName = window.top.window.$("#shopIdNew").find("option:selected").text();
                                order.buyerNick = window.top.window.$("#buyerNickNew").val();
                                order.storId = window.top.window.$("#storIdNew").val();
                                order.storName = window.top.window.$("#storIdNew").find("option:selected").text();
                                ;
                                order.payMode = window.top.window.$("#payModeNew").val();
                                order.paidFee = window.top.window.$("#paidFeeNew").val();
                                order.paidDate = window.top.window.$("#paidDateNew").val();
                                order.lgstId = window.top.window.$("#lgstIdNew").val();
                                order.lgstName = window.top.window.$("#lgstIdNew").find("option:selected").text();
                                ;
                                order.lgstNo = window.top.window.$("#lgstNoNew").val();
                                order.lgstFee = window.top.window.$("#lgstFeeNew").val();
                                order.remark = window.top.window.$("#remarkNew").val();
                                order.salesman = window.top.window.$("#salesmanNew").val();
                                order.cons = window.top.window.$("#consNew").val();
                                order.consTel = window.top.window.$("#consTelNew").val();
                                order.consMobile = window.top.window.$("#consMobileNew").val();
                                order.consAddr = window.top.window.$("#consAddrNew").val();
                                order.consPostCode = window.top.window.$("#consPostCodeNew").val();
                                if (window.top.window.$("#provNameNew").val() != '') {
                                    order.provName = window.top.window.$("#provNameNew").find("option:selected").text();
                                    order.areaCoding = window.top.window.$("#provNameNew").val();
                                } else {
                                    order.provName = "";
                                    order.areaCoding = "";
                                }
                                if (window.top.window.$("#cityNameNew").val() != '') {
                                    order.cityName = window.top.window.$("#cityNameNew").find("option:selected").text();
                                    order.areaCoding = window.top.window.$("#cityNameNew").val();
                                } else {
                                    order.cityName = "";
//                                    order.areaCoding = "";
                                }
                                if (window.top.window.$("#distNameNew").val() != '') {
                                    order.distName = window.top.window.$("#distNameNew").find("option:selected").text();
                                    order.areaCoding = window.top.window.$("#distNameNew").val();
                                } else {
                                    order.distName = "";
//                                    order.areaCoding = "";
                                }
                                orderInfo.order = order;
                                if ("y"== window.top.window.$("#isNew").val()){
                                    orderInfo.action = "insert";    
                                } else {
                                    orderInfo.action = "update";
                                    order.orderId = window.top.window.$("#orderIdNewOrderPage").val();
                                }
                                orderInfo.checkPrice = "y";
                                orderInfo.checkCash = "y";
                                // 表值同步
                                if (nEditing != null) {
                                    saveRow(newOrderTable, nEditing);
                                    nEditing = null;
                                }

                                // 规格表的数据取得
                                var row = 0;
                                var isAllVir = "1";
                                var rule = /^([1-9]\d{0,9}|0)([.]?|(\.\d{1,2})?)$/;; //小数
                                var rule1 = /^\d{1,8}$/;;                               //数字
//                                return this.optional(element) || (rule.test(value));
                                var actPayAmount = 0;  // 计算商品实际支付金额之和
                                window.top.window.$('#newOrderTable tbody tr').each(
                                        function(index) {
                                            var orderSku = new Object();
                                            var aData = newOrderTable.fnGetData(this);

                                            row++;

                                            if (aData != null &&  (aData[8] !== null && aData[8] !== undefined && $.trim(aData[8]) !== '')
                                                    && (aData[5] !== null && aData[5] !== undefined && $.trim(aData[5]) !== '')) {
                                                if(!rule1.test(aData[5])){
                                                    msg = "数量输入格式有问题";
                                                    return false;
                                                }
                                                if(!rule.test(aData[8])){
                                                    msg = "实际单价输入格式有问题";
                                                    return false;
                                                }
                                                if (isAllVir == "1" && $(this).find("a").html()=="删除" && "赠" != aData[0]){
                                                    isAllVir = "0";
                                                }
                                                if ($(this).find("a").attr("orderskuid")!=null && $(this).find("a").attr("orderskuid")!=undefined && $(this).find("a").attr("orderskuid")!=""){
                                                    orderSku.action = "update";
                                                    orderSku.orderSkuId = $(this).find("a").attr("orderskuid");
                                                } else {
                                                    orderSku.action = "insert";
                                                    if ("n"== window.top.window.$("#isNew").val()){
                                                        orderSku.orderId = window.top.window.$("#orderIdNewOrderPage").val();
                                                    }
                                                    
                                                }                                                
                                                if ($(this).find("a").html().indexOf("删除")!=-1){
                                                    orderSku.deleted = "n";
                                                } else if ($(this).find("a").html().indexOf("恢复")!=-1){
                                                    orderSku.deleted = "y";
                                                }
                                                if ("赠" == aData[0]) {
                                                    orderSku.isGift = "y";
                                                    orderSku.isVirt = "n";
                                                } else if ("虚" == aData[0]) {
                                                    orderSku.isGift = "n";
                                                    orderSku.isVirt = "y";
                                                } else {
                                                    orderSku.isGift = "n";
                                                    orderSku.isVirt = "n";
                                                }
//                                                var index = aData[1].split("|")[1];
//                                                index = index.split(":")[1];
                                                orderSku.goodsId = GoodsSkuMap[index].goodsId;
                                                orderSku.skuId = GoodsSkuMap[index].skuId;
                                                orderSku.goodsSkuCost = GoodsSkuMap[index].goodsSkuCost;
                                                orderSku.goodsCode = aData[1];//GoodsSkuMap[index].goodsCode;
                                                orderSku.goodsName = aData[2];//GoodsSkuMap[index].goodsName;
                                                orderSku.skuCode = aData[3];//GoodsSkuMap[index].skuCode;
                                                orderSku.skuName = aData[4];//GoodsSkuMap[index].skuName;
                                                orderSku.qty = aData[5];
                                                orderSku.salePrice = aData[6];
                                                
                                                if(aData[12].indexOf('恢复')<0){
                                                    actPayAmount += aData[10];
                                                }

                                                if (aData[8] == '' || aData[8] == null || aData[8] == undefined) {
                                                    orderSku.factUnitPrice = 0;
                                                } else {
                                                    orderSku.factUnitPrice = aData[8];
                                                }
                                                orderSku.remark = aData[11];
                                                arrSku.push(orderSku);
                                            } else {
                                                flg = false
                                                return false;
                                            }
                                        });
                                if (row > 0) {
                                    if (msg!=""){
                                        window.top.window.showModalAlert(msg);
                                        return;
                                    }
                                    if (!flg) {
                                        window.top.window.showModalAlert("商品列表中有必须输入项目为空的情况");
                                        return;
                                    }
                                } else {
                                    window.top.window.showModalAlert("商品列表为空");
                                    return;
                                }
                                
                                if (isAllVir == "1"){
                                    window.top.window.showModalAlert("没有非赠品的商品");
                                    return;
                                }

                                
                                if(!order.tradeStatus){
                                    var _actPayAmount = actPayAmount;// 实际支付金额之和
                                    var _actTotalPayAmount = order.paidFee-order.lgstFee;// 订单支付金额-物流费用
                                    if(_actPayAmount-_actTotalPayAmount!=0){
                                        if(order.orderType=="货到付款"){
                                            var r = confirm("商品支付金额与订单支付金额不匹配，是否继续保存？");
                                            if(!r){
                                                return;
                                            }
                                        }else{
                                            window.top.window.showModalAlert("商品支付金额与订单支付金额不匹配,请调整后保存");
                                            return;
                                        }
                                    }
                                }
                                //        
                                orderInfo.arrSku = arrSku;
                                // alert(JSON.stringify(orderInfo));
                                // $('#newOrderPage').modal('hide'); test
                                // 父窗体归还本页的编辑对话框

                                // 后台交互
                                makeData(orderInfo, 'y', 'y');

                            });

                    function makeData(orderInfo, checkPrice, checkCash) {
                        orderInfo.checkPrice = checkPrice;
                        orderInfo.checkCash = checkCash;
                        var loading = window.top.window.getIndexBusyOverlay();
                        $.ajax({
                            type : "POST",
                            url : "/order/createOrder.action",
                            data : JSON.stringify(orderInfo),
                            contentType : "application/json;charset=utf-8",
                            dataType : "json",
                            beforeSend:function(){
                                if(loading) {
                                	loading.settext("正在处理中，请稍后...");
                                }
                            },
                            success : function(data) {
                            	loading.remove();
                                window.top.window.returnCustomModalDialog();
                                if (data.success == "y") {
                                    $('#newOrderPage').modal('hide');
                                    $("div .active").each(function() {
                                        switch ($(this).attr("id")) {
                                        case "waitVerifyTab": // 待审核
                                            waitVerify.draw();
                                            break;
                                        case "waitAssignTab": // 待分派
                                            waitAssign.draw();
                                            break;
                                        case "shippingTab": // 发货中
                                            shipping.draw();
                                            break;
                                        case "shippedTab": // 已发货
                                            shipped.draw();
                                            break;
                                        case "completeTab": // 已完成
                                            complete.draw();
                                            break;
                                        case "cancelTab": // 已废弃
                                            cancel.draw();
                                            break;
                                        default:
                                            break;
                                        }
                                    });
                                    window.top.window.showScoMessage('ok', '数据更新成功');

                                } else if (data.success == "q_Price") {
                                    var r = confirm(data.errormessage);
                                    if (r == true) {
                                        makeData(orderInfo, "n", orderInfo.checkCash);
                                    } else {
                                        var editDialog = window.top.window.borrowCustomModalDialog($("#newOrderPage"));
                                        editDialog.modal({
                                            show : true,
                                            backdrop : 'static'
                                        });
                                    }
                                } else if (data.success == "q_cash") {
                                    var r = confirm(data.errormessage);
                                    if (r == true) {
                                        makeData(orderInfo, orderInfo.checkPrice, "n");
                                    } else {
                                        var editDialog = window.top.window.borrowCustomModalDialog($("#newOrderPage"));
                                        editDialog.modal({
                                            show : true,
                                            backdrop : 'static'
                                        });
                                    }
                                } else {
                                    window.top.window.showModalAlert(data.errormessage);
                                    var editDialog = window.top.window.borrowCustomModalDialog($("#newOrderPage"));
                                    editDialog.modal({
                                        show : true,
                                        backdrop : 'static'
                                    });
                                }

                            },
                            error : function(XMLHttpRequest, textStatus) {
                            	loading.remove();
                                if (XMLHttpRequest.status == 500) {
                                    var result = eval("(" + XMLHttpRequest.responseText + ")");
                                    alert(result.errorObject.errorText);
                                }
                            }
                        });
                    }

                    /**
                     * 废弃订单
                     */
                    $("#btnCancleOrder")
                            .click(
                                    function() {
                                        // 父窗体归还本页的编辑对话框
                                        window.top.window.returnCustomModalDialog();

                                        // 输入有效性验证
                                        if ($("#cancelRemark").val() == "" || $("#cancelRemark").val() == null
                                                || $("#cancelRemark").val() == undefined) {
                                            window.top.window.showModalAlert("废弃订单的原因不能为空");
                                            // 父窗体借用本页的编辑对话框
                                            window.top.window.borrowCustomModalDialog($("#modalCancleOrder"));
                                            return false;
                                        }

                                        var orderArry = new Array();
                                        $("div .active").each(function() {
                                            switch ($(this).attr("id")) {
                                            case "waitVerifyTab": // 待审核
                                                $('input:checkbox[name=chkOrdera]:checked').each(function(i) {
                                                    orderArry.push($(this).attr("orderId"));
                                                });
                                                break;
                                            case "waitAssignTab": // 待分派
                                                break;
                                            case "shippingTab": // 发货中
                                                break;
                                            case "shippedTab": // 已发货
                                                break;
                                            case "completeTab": // 已完成
                                                break;
                                            case "cancelTab": // 已废弃
                                                break;
                                            default:
                                                break;
                                            }
                                        });

                                        var cancelRemark =$("#cancelRemark").val();
                                        var loading = window.top.window.getIndexBusyOverlay();
                                        $.ajax({
                                            type : "POST",
                                            url : "/order/abandonOrder.action?strType=y&cancelRemark=" + encodeURI(cancelRemark),
                                            // contentType : "application/json;charset=utf-8",
                                            // dataType : "json",
                                            data:{"orderId":orderArry.join(",")},
                                            beforeSend:function(){
                                                if(loading) {
                                                	loading.settext("正在处理中，请稍后...");
                                                }
                                            },
                                            success : function(data) {
                                            	loading.remove();
                                                if (data.result == "success") {
                                                	$("#btnCancleOrderF").click();//隐藏弹出层
                                                    window.top.window.showScoMessage('ok', "废弃成功");
                                                    refresh();
                                                } else {
                                                    var errormessage = data.msg.replace(/n/g, "<br/>");
                                                    window.top.window.showModalAlertPretty(errormessage);
                                                }
                                            },
                                            error : function(XMLHttpRequest, textStatus) {
                                            	loading.remove();
                                                if (XMLHttpRequest.status == 500) {
                                                    var result = eval("(" + XMLHttpRequest.responseText + ")");
                                                    alert(result.errorObject.errorText);
                                                }
                                            }
                                        });
                                    });

                    // 对话框关闭事件发生
                    $('#modalCancleOrder').on('hide.bs.modal', function() {
                        // 父窗体归还本页的编辑对话框
                        window.top.window.returnCustomModalDialog();
                    })

                    /**
                     * 取消废弃订单
                     */
                    $("#btnRevokeCancelOrder").click(function() {
                        // 父窗体归还本页的编辑对话框
                        window.top.window.returnCustomModalDialog();

                        var orderArry = new Array();
                        $("div .active").each(function() {
                            switch ($(this).attr("id")) {
                            case "waitVerifyTab": // 待审核
                                break;
                            case "waitAssignTab": // 待分派
                                break;
                            case "shippingTab": // 发货中
                                break;
                            case "shippedTab": // 已发货
                                break;
                            case "completeTab": // 已完成
                                break;
                            case "cancelTab": // 已废弃
                                $('input:checkbox[name=chkOrdercancel]:checked').each(function(i) {
                                    orderArry.push($(this).attr("orderId"));
                                });
                                break;
                            default:
                                break;
                            }
                        });

                        var loading = window.top.window.getIndexBusyOverlay();
                        $.ajax({
                            type : "POST",
                            url : "/order/abandonOrder.action?strType=n&cancelRemark=",
                            // contentType : "application/json;charset=utf-8",
                            // dataType : "json",
                            data:{"orderId":orderArry.join(",")},
                            beforeSend:function(){
                                if(loading) {
                                	loading.settext("正在处理中，请稍后...");
                                }
                            },
                            success : function(data) {
                            	loading.remove();
                                if (data.result == "success") {
                                	$('#modalRevokeCancelOrder').find("#btnRevokeCancel").click();
                                    window.top.window.showScoMessage('ok', "取消废弃成功");
                                    refresh();
                                } else {
                                    window.top.window.showModalAlert(data.msg);
                                    window.top.window.borrowCustomModalDialog($("#modalRevokeCancelOrder"));
                                }
                            },
                            error : function(XMLHttpRequest, textStatus) {
                            	loading.remove();
                                if (XMLHttpRequest.status == 500) {
                                    var result = eval("(" + XMLHttpRequest.responseText + ")");
                                    alert(result.errorObject.errorText);
                                }
                            }
                        });
                    });

                    /**
                     * 批量追加备注
                     */
                    $("#btnBatchRemark").click(
                        function () {
                            var xval = window.top.window.getIndexBusyOverlay();
                            if(xval) {
                                xval.settext("正在处理中，请稍后...");
                            }
                            // // 父窗体归还本页的编辑对话框
                            // window.top.window.returnCustomModalDialog();
                            setTimeout(function() {
                                var orderArry = new Array();
                                $("div .active").each(function () {
                                    switch ($(this).attr("id")) {
                                        case "waitVerifyTab": // 待审核
                                            $('input:checkbox[name=chkOrdera]:checked').each(function (i) {
                                                orderArry.push($(this).attr("orderId"));
                                            });
                                            break;
                                        case "waitAssignTab": // 待分派
                                            $('input:checkbox[name=chkOrderi]:checked').each(function (i) {
                                                orderArry.push($(this).attr("orderId"));
                                            });
                                            break;
                                        case "shippingTab": // 发货中
                                            $('input:checkbox[name=chkOrderk]:checked').each(function (i) {
                                                orderArry.push($(this).attr("orderId"));
                                            });
                                            break;
                                        case "shippedTab": // 已发货
                                            $('input:checkbox[name=chkOrderr]:checked').each(function (i) {
                                                orderArry.push($(this).attr("orderId"));
                                            });
                                            break;
                                        case "completeTab": // 已完成
                                            break;
                                        case "cancelTab": // 已废弃
                                            break;
                                        default:
                                            break;
                                    }
                                });

                                $.ajax({
                                    type: "POST",
                                    url: "/order/batchUpdateOrderMemo.action?addRemark="
                                    + window.top.window.$("#addRemark").val(),
                                    // contentType: "application/json;charset=utf-8",
                                    // dataType: "json",
                                    data: {"orderId": orderArry.join(",")},
                                    success: function (data) {
                                    	xval.remove();
                                        // 父窗体归还本页的编辑对话框
                                        window.top.window.returnCustomModalDialog();
                                        if (data.result == "success") {
                                            $('#modalBatchRemark').find("#btnBatchRemarkCancel").click();
                                            window.top.window.showModalAlertPretty("批量执行完成：<br/>" + data.msg);
                                        } else {
                                            window.top.window.showModalAlert(data.msg);
                                            window.top.window.borrowCustomModalDialog($("#modalBatchRemark"));
                                        }
                                    },
                                    error: function (XMLHttpRequest, textStatus) {
                                    	xval.remove();
                                        if (XMLHttpRequest.status == 500) {
                                            var result = eval("(" + XMLHttpRequest.responseText + ")");
                                            alert(result.errorObject.errorText);
                                        }
                                    }
                                });
                            });
                        });

                    // 对话框关闭事件发生
                    $('#modalRevokeCancelOrder').on('hide.bs.modal', function() {
                        // 父窗体归还本页的编辑对话框
                        window.top.window.returnCustomModalDialog();
                    })

                    // 对话框关闭事件发生
                    $('#assignOrderPage').on('hide.bs.modal', function() {
                        // 父窗体归还本页的编辑对话框
                        window.top.window.returnCustomModalDialog();
                    })
                    // 对话框关闭事件发生
                    $('#modalBatchRemark').on('hide.bs.modal', function() {
                        // 父窗体归还本页的编辑对话框
                        window.top.window.returnCustomModalDialog();
                    })
                    // 对话框关闭事件发生
                    $('#modalBatchSalesRemark').on('hide.bs.modal', function() {
                        // 父窗体归还本页的编辑对话框
                        window.top.window.returnCustomModalDialog();
                    })
                    // 对话框关闭事件发生
                    $('#modalBatchStor').on('hide.bs.modal', function() {
                        // 父窗体归还本页的编辑对话框
                        window.top.window.returnCustomModalDialog();
                    })
                    // 对话框关闭事件发生
                    $('#modalBatchLgst').on('hide.bs.modal', function() {
                        // 父窗体归还本页的编辑对话框
                        window.top.window.returnCustomModalDialog();
                    })
                    // 对话框关闭事件发生
                    $('#modalDownLoad').on('hide.bs.modal', function() {
                        // 父窗体归还本页的编辑对话框
                        window.top.window.returnCustomModalDialog();
                    })

                    $('#shipOrderTable').on('click', 'a.edit', function(e) {
                        e.preventDefault();
                        var nRow = $(this).parents('tr')[0];
                        if (nEditingshipOrder !== null && nEditingshipOrder != nRow) {
                            rollbackRowshipOrder(shipOrderTable, nEditingshipOrder);
                            editshipOrderRow(shipOrderTable, nRow);
                            nEditingshipOrder = nRow;
                        } else if (nEditingshipOrder == nRow && this.innerHTML == "保存") {
                            saveshipOrderRow(shipOrderTable, nEditingshipOrder);
                            nEditingshipOrder = null;
                        } else {
                            editshipOrderRow(shipOrderTable, nRow);
                            nEditingshipOrder = nRow;
                        }
                    });

                    /**
                     * btnAssignAdd分派
                     */
                    $("#btnAssignAdd").click(function() {
                        emptyLgstCompany = "y";
                        hasrefund = "y";
                        orderIdAssign = $(this).attr("orderId");
                        if(!$('#assignOrderPage',window.top.document).find("#frmOrderAssign").valid()) {
                       	$("#btnAssignAdd").click();
                            return;
                        }
                        window.top.window.showModalConfirms("确定分派该订单吗?", doAssignorder);
                        // var id = $(this).attr("orderId");
                        // window.top.window.$("#modalConfirmContent").text("确定分派该订单吗?");
                        // window.top.window.$('#btnModalOK').unbind();
                        // window.top.window.$("#btnModalOK").on('click',
                        // '',{id:id}, doAssignorder);
                        // window.top.window.$('#modal-confirm').modal({show:true,
                        // backdrop:'static'});
                    });
                });

//a的button变灰
function disableButten(btnId){
    $("#"+btnId).attr("disabled","disabled");
    //$("#"+btnId).addClass("btn-disable");
    $("#"+btnId).removeClass("btn-info");
    $("#"+btnId).css("background","#777777"); 
}
//a的button恢复好用状态
function enableButten(btnId){
    $("#"+btnId).removeAttr("disabled");
    $("#"+btnId).addClass("btn-info");
    $("#"+btnId).css("background","");
    //$("#"+btnId).removeClass("btn-disable");
}

/**
 * 待审核 列表
 * 
 * @returns
 */
function showWaitVerifyTab() {
    $("#cancelOrder").show();
    $("#revokeCancelOrder").hide();
    $("#inspectedOrder").show();
    $("#auditOrder").show();
    $("#unAuditOrder").hide();
    $("#cancelInspectedOrder").show();
    $("#finishOrder").hide();
    
    $("#sign").show();
    $("#onAuto").show();
    $("#offAuto").show();
    $("#onLock").show();
    $("#offLock").show();

    $("#batch").show();
    $("#batchRemark").show();
    $("#batchCompany").show();
    $("#batchStore").show();
    
    // 如果已经初期化过，不用重新定义，直接重画表格
    if (waitVerify != null && waitVerify != undefined && "" != waitVerify) {
        waitVerify.draw();
        return;
    }
    waitVerify = $('#waitVerifyTable').DataTable({
        "scrollX" : "100%",
        "scrollY" : "410px",
        "scrollCollapse" : false,
        "processing" : true,
        "serverSide" : true,
        "lengthMenu" : [ [ 10, 25, 50, 100, 500, 1000 ], [ 10, 25, 50, 100, 500, 1000 ] ],
        "dom" : '<"bottom"rtflp>',
        "searching" : false,
        "pagingType" : "full_numbers",
        "deferRender" : true,
        "ajax" : {
            "url" : "/order/getWaitVerifyTable.action",
            "data" : function(d) {
                d.quickSearch = quickSearch;
                d.formJson = JSON.stringify(searchCondition);
            }
        },
        "tableTools" : {
            "sRowSelect" : "bootstrap"
        },
        "columns" : [ {
            "data" : "sonShow"
        }, {
            "data" : "chk"
        }, {
            "data" : "sign",
            "render" : function(data, type, row, meta) {
               var returnType = "";
               var spaceFirst = "&nbsp;&nbsp;";
               var centerSpace = "&nbsp;&nbsp;&nbsp;&nbsp;";
               var repairSpace = "&nbsp;&nbsp;";
               if(row.customerService == ""){
                   if(row.merge == ""){
                       if(row.inspection == ""){
                           returnType = spaceFirst + data +centerSpace + repairSpace + centerSpace + repairSpace+ centerSpace + repairSpace ;
                       }else{
                           returnType = spaceFirst + data + centerSpace + repairSpace + centerSpace + repairSpace + centerSpace + row.inspection;
                       }
                   }else {
                       if(row.inspection == ""){
                           returnType = spaceFirst + data + centerSpace + repairSpace + centerSpace + row.merge + centerSpace + repairSpace ;
                       }else{
                           returnType = spaceFirst + data + centerSpace + repairSpace + centerSpace + row.merge + centerSpace + row.inspection;
                       }
                   }
               }else{
                   if(row.merge == ""){
                       if(row.inspection == ""){
                           returnType = spaceFirst + data + centerSpace + row.customerService + centerSpace + repairSpace + centerSpace + repairSpace ;
                       }else{
                           returnType = spaceFirst + data + centerSpace + row.customerService + centerSpace + repairSpace + centerSpace + row.inspection;
                       }
                   }else {
                       if(row.inspection == ""){
                           returnType = spaceFirst + data + centerSpace + row.customerService + centerSpace + row.merge + centerSpace + repairSpace ;
                       }else{
                           returnType = spaceFirst + data + centerSpace + row.customerService + centerSpace + row.merge + centerSpace + row.inspection;
                       }
                   }
               }
               return returnType;
            }
        }, 
        /*{
            "data" : "customerService"
        }, {
            "data" : "merge"
        }, {
            "data" : "inspection"
        }, */
        {
            "data" : "ecFlagShow"
        }, {
            "data" : "shopName"
        }, {
            "data" : "buyerNick"
        }, {
            "data" : "tradeCode"
        }, {
            "data" : "orderCode"
        },
        //     {
        //     "data" : "status"
        // },
            {
            "data" : "orderTime"
        }, {
            "data" : "paidDate"
        }, {
            "data" : "disQuestion"
        },{
            "data" : "custRemark"
        }, {
            "data" : "salesRemark"
        }, {
            "data" : "operation"
        } ],
        "columnDefs" : [ {
            "orderable" : false,
            "targets" : [ 0 ]
        }, {
            "orderable" : false,
            "targets" : [ 1 ]
        }, {
//        	"className" : "truncate-text tooltip-column-detail",
            "orderable" : false,
            "targets" : [ 2 ]
        }, /*{
            "orderable" : false,
            "targets" : [ 3 ]
        }, {
            "orderable" : false,
            "targets" : [ 4 ]
        }, {
            "orderable" : false,
            "targets" : [ 5 ]
        }, */{
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 3 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 4 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 5 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 6 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 7 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 8 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 9 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 10 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 11 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 12 ]
        }],

        "order" : [ [8, "desc" ] ]
    }).on('draw.dt',  function() {
    	//解决因滚动条导致的列对不齐问题
        $(".dataTables_scrollBody").css("overflow-y","overlay");
        $("#waitVerifyTable").find("th.sorting_asc").removeClass("sorting_asc");
        
//        turn_on_iCheck($("#waitVerifyTab"));
//        $("#chkAlla").on("ifChanged", function() {
//            if ($("#chkAlla").is(":checked")) {
//            	$("#waitVerifyTab").find(".icheck").iCheck("check");
//            } else {
//            	$("#waitVerifyTab").find(".icheck").iCheck("uncheck");
//            }
//        });
    });
    
}
/**
 * 待分派
 * 
 * @returns
 */
function showWaitAssignTab() {
    $("#cancelOrder").hide();
    $("#revokeCancelOrder").hide();
    $("#inspectedOrder").hide();
    $("#auditOrder").hide();
    $("#unAuditOrder").show();
    $("#cancelInspectedOrder").hide();
    $("#finishOrder").hide();
    
    $("#sign").show();
    $("#onAuto").hide();
    $("#offAuto").show();
    $("#onLock").show();
    $("#offLock").show();

    $("#batch").show();
    $("#batchRemark").show();
    $("#batchCompany").show();
    $("#batchStore").show();

    // 如果已经初期化过，不用重新定义，直接重画表格
    if (waitAssign != null && waitAssign != undefined && "" != waitAssign) {
        waitAssign.draw();
        return;
    }
    waitAssign = $('#waitAssignTable').DataTable({
        "processing" : true,
        "scrollX" : "100%",
        "scrollY" : "410px",
        "scrollCollapse" : false,
        "processing" : true,
        "serverSide" : true,
        "lengthMenu" : [ [ 10, 25, 50, 100, 500, 1000 ], [ 10, 25, 50, 100, 500, 1000 ] ],
        "dom" : '<"bottom"rtflp>',
        "searching" : false,
        "pagingType" : "full_numbers",
        "deferRender" : true,
        "ajax" : {
            "url" : "/order/getWaitAssignTable.action",
            "data" : function(d) {
                d.quickSearch = quickSearch;
                d.formJson = JSON.stringify(searchCondition);
            }
        },
        "tableTools" : {
            "sRowSelect" : "bootstrap"
        },
        "columns" : [ {
            "data" : "sonShow"
        }, {
            "data" : "chk"
        }, {
            "data" : "sign",
            "render" : function(data, type, row, meta) {
 		       var returnType = "";
 		       var spaceFirst = "&nbsp;&nbsp;";
 		       var centerSpace = "&nbsp;&nbsp;&nbsp;&nbsp;";
 		       var repairSpace = "&nbsp;&nbsp;";
 		       if(row.customerService == ""){
 		    	   if(row.merge == ""){
 		    		   returnType = spaceFirst + data +centerSpace + repairSpace + centerSpace + repairSpace;
 		    	   }else {
 		    		   returnType = spaceFirst + data + centerSpace + repairSpace + centerSpace + row.merge;
 		    	   }
 		       }else{
 		    	   if(row.merge == ""){
 		    		   returnType = spaceFirst + data + centerSpace + row.customerService + centerSpace + repairSpace;
 		    	   }else {
 		    		   returnType = spaceFirst + data + centerSpace + row.customerService + centerSpace + row.merge;
 		    	   }
 		       }
 		       return returnType;
 	        }
        }, /*{
            "data" : "customerService"
        }, {
            "data" : "merge"
        }, */{
            "data" : "ecFlagShow"
        }, {
            "data" : "shopName"
        }, {
            "data" : "buyerNick"
        }, {
            "data" : "tradeCode"
        }, {
            "data" : "orderCode"
        },
        //     {
        //     "data" : "status"
        // },
            {
            "data" : "orderTime"
        }, {
            "data" : "paidDate"
        },{
            "data" : "custRemark"
        }, {
            "data" : "salesRemark"
        }, {
            "data" : "operation"
        } ],
        "columnDefs" : [ {
            "orderable" : false,
            "targets" : [ 0 ]
        }, {
            "orderable" : false,
            "targets" : [ 1 ]
        }, {
//        	"className" : "truncate-text tooltip-column-detail",
            "orderable" : false,
            "targets" : [ 2 ]
        },/* {
            "orderable" : false,
            "targets" : [ 3 ]
        }, {
            "orderable" : false,
            "targets" : [ 4 ]
        }, */{
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 3 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 4 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 5 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 6 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 7 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 8 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 9 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 10 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 11 ]
        }
        // , {
        //     "className" : "truncate-text tooltip-column-detail",
        //     "targets" : [ 10 ]
        // }
        ],
        "order" : [ [ 8, "desc" ] ]
    }).on('draw.dt',  function() {
    	//解决因滚动条导致的列对不齐问题
        $(".dataTables_scrollBody").css("overflow-y","overlay");
        
        $("#waitVerifyTable").find("th.sorting_asc").removeClass("sorting_asc");
        
//        turn_on_iCheck($("#waitAssignTab"));
//        $("#chkAlli").on("ifChanged", function() {
//            if ($("#chkAlli").is(":checked")) {
//            	$("#waitAssignTab").find(".icheck").iCheck("check");
//            } else {
//            	$("#waitAssignTab").find(".icheck").iCheck("uncheck");
//            }
//        });
    });
}

/**
 * 发货中
 * 
 * @returns
 */
function showShippingTab() {
    $("#cancelOrder").hide();
    $("#revokeCancelOrder").hide();
    $("#inspectedOrder").hide();
    $("#auditOrder").hide();
    $("#unAuditOrder").hide();
    $("#cancelInspectedOrder").hide();
    $("#finishOrder").hide();

    $("#sign").show();
    $("#onAuto").hide();
    $("#offAuto").show();
    $("#onLock").show();
    $("#offLock").show();

    $("#batch").show();
    $("#batchRemark").show();
    $("#batchCompany").hide();
    $("#batchStore").hide();

    // 如果已经初期化过，不用重新定义，直接重画表格
    if (shipping != null && shipping != undefined && "" != shipping) {
        shipping.draw();
        return;
    }
    shipping = $('#shippingTable').DataTable({
        "processing" : true,
        "scrollX" : "100%",
        "scrollY" : "410px",
        "scrollCollapse" : false,
        "serverSide" : true,
        "lengthMenu" : [ [ 10, 25, 50, 100, 500, 1000 ], [ 10, 25, 50, 100, 500, 1000 ] ],
        "dom" : '<"bottom"rtflp>',
        "searching" : false,
        "pagingType" : "full_numbers",
        "deferRender" : true,
        "ajax" : {
            "url" : "/order/getShippingTable.action",
            "data" : function(d) {
                d.quickSearch = quickSearch;
                d.formJson = JSON.stringify(searchCondition);
            }
        },
        "tableTools" : {
            "sRowSelect" : "bootstrap"
        },
        "columns" : [ {
            "data" : "sonShow"
        }, {
            "data" : "chk"
        }, {
            "data" : "sign",
            "render" : function(data, type, row, meta) {
  		       var returnType = "";
  		       var spaceFirst = "&nbsp;&nbsp;";
  		       var centerSpace = "&nbsp;&nbsp;&nbsp;&nbsp;";
  		       var repairSpace = "&nbsp;&nbsp;";
  		       if(row.customerService == ""){
  		    	   if(row.merge == ""){
  		    		   returnType = spaceFirst + data +centerSpace + repairSpace + centerSpace + repairSpace;
  		    	   }else {
  		    		   returnType = spaceFirst + data + centerSpace + repairSpace + centerSpace + row.merge;
  		    	   }
  		       }else{
  		    	   if(row.merge == ""){
  		    		   returnType = spaceFirst + data + centerSpace + row.customerService + centerSpace + repairSpace;
  		    	   }else {
  		    		   returnType = spaceFirst + data + centerSpace + row.customerService + centerSpace + row.merge;
  		    	   }
  		       }
  		       return returnType;
  	        }
        }, /*{
            "data" : "customerService"
        }, {
            "data" : "merge"
        },*/ {
            "data" : "ecFlagShow"
        }, {
            "data" : "shopName"
        }, {
            "data" : "buyerNick"
        }, {
            "data" : "tradeCode"
        }, {
            "data" : "orderCode"
        },
        //     {
        //     "data" : "status"
        // },
            {
            "data" : "orderTime"
        }, {
            "data" : "paidDate"
        },{
            "data" : "custRemark"
        }, {
            "data" : "salesRemark"
        }, {
            "data" : "operation"
        } ],
        "columnDefs" : [ {
            "orderable" : false,
            "targets" : [ 0 ]
        }, {
            "orderable" : false,
            "targets" : [ 1 ]
        }, {
            "orderable" : false,
//            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 2 ]
        },/* {
            "orderable" : false,
            "targets" : [ 3 ]
        }, {
            "orderable" : false,
            "targets" : [ 4 ]
        }, */{
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 3 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 4 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 5 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 6 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 7 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 8 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 9 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 10 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 11 ]
        }
        // , {
        //     "className" : "truncate-text tooltip-column-detail",
        //     "targets" : [ 10 ]
        // }
        ],
        "order" : [ [ 8, "desc" ] ]
    }).on('draw.dt',  function() {
    	//解决因滚动条导致的列对不齐问题
        $(".dataTables_scrollBody").css("overflow-y","overlay");
        
        $("#waitVerifyTable").find("th.sorting_asc").removeClass("sorting_asc");
        
//        turn_on_iCheck($("#shippingTab"));
//        $("#chkAllk").on("ifChanged", function() {
//            if ($("#chkAllk").is(":checked")) {
//            	$("#shippingTab").find(".icheck").iCheck("check");
//            } else {
//            	$("#shippingTab").find(".icheck").iCheck("uncheck");
//            }
//        });
    });
}

/**
 * 已发货
 * 
 * @returns
 */
function showShippedTab() {
    $("#cancelOrder").hide();
    $("#revokeCancelOrder").hide();
    $("#inspectedOrder").hide();
    $("#auditOrder").hide();
    $("#unAuditOrder").hide();
    $("#cancelInspectedOrder").hide();
    $("#finishOrder").show();
    
    $("#sign").hide();
    $("#onAuto").hide();
    $("#offAuto").hide();
    $("#onLock").hide();
    $("#offLock").hide();

    $("#batch").show();
    $("#batchRemark").show();
    $("#batchCompany").hide();
    $("#batchStore").hide();

    // 如果已经初期化过，不用重新定义，直接重画表格
    if (shipped != null && shipped != undefined && "" != shipped) {
        shipped.draw();
        return;
    }
    shipped = $('#shippedTable').DataTable({
        "processing" : true,
        "scrollX" : "100%",
        "scrollY" : "410px",
        "scrollCollapse" : false,
        "serverSide" : true,
        "lengthMenu" : [ [ 10, 25, 50, 100, 500, 1000 ], [ 10, 25, 50, 100, 500, 1000 ] ],
        "dom" : '<"bottom"rtflp>',
        "searching" : false,
        "pagingType" : "full_numbers",
        "deferRender" : true,
        "ajax" : {
            "url" : "/order/getShippedTable.action",
            "data" : function(d) {
                d.quickSearch = quickSearch;
                d.formJson = JSON.stringify(searchCondition);
            }
        },
        "tableTools" : {
            "sRowSelect" : "bootstrap"
        },
        "columns" : [ {
            "data" : "sonShow"
        }, {
            "data" : "chk"
        }, {
            "data" : "sign",
            "render" : function(data, type, row, meta) {
   		       var returnType = "";
   		       var spaceFirst = "&nbsp;&nbsp;";
   		       var centerSpace = "&nbsp;&nbsp;&nbsp;&nbsp;";
   		       var repairSpace = "&nbsp;&nbsp;";
   		       if(row.customerService == ""){
   		    	   if(row.merge == ""){
   		    		   returnType = spaceFirst + data +centerSpace + repairSpace + centerSpace + repairSpace;
   		    	   }else {
   		    		   returnType = spaceFirst + data + centerSpace + repairSpace + centerSpace + row.merge;
   		    	   }
   		       }else{
   		    	   if(row.merge == ""){
   		    		   returnType = spaceFirst + data + centerSpace + row.customerService + centerSpace + repairSpace;
   		    	   }else {
   		    		   returnType = spaceFirst + data + centerSpace + row.customerService + centerSpace + row.merge;
   		    	   }
   		       }
   		       return returnType;
   	        }
        },/* {
            "data" : "customerService"
        }, {
            "data" : "merge"
        },*/ {
            "data" : "ecFlagShow"
        }, {
            "data" : "shopName"
        }, {
            "data" : "buyerNick"
        }, {
            "data" : "tradeCode"
        }, {
            "data" : "orderCode"
        },
        //     {
        //     "data" : "status"
        // },
            {
            "data" : "orderTime"
        }, {
            "data" : "paidDate"
        }, {
            "data" : "custRemark"
        }, {
            "data" : "salesRemark"
        }, {
            "data" : "operation"
        } ],
        "columnDefs" : [ {
            "orderable" : false,
            "targets" : [ 0 ]
        }, {
            "orderable" : false,
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 1 ]
        }, {
            "orderable" : false,
            "targets" : [ 2 ]
        }, /*{
            "orderable" : false,
            "targets" : [ 3 ]
        }, {
            "orderable" : false,
            "targets" : [ 4 ]
        }, */{
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 3 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 4 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 5 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 6 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 7 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 8 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 9 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 10 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 11 ]
        }
        // , {
        //     "className" : "truncate-text tooltip-column-detail",
        //     "targets" : [ 10 ]
        // }
        ],
        "order" : [ [ 8, "desc" ] ]
    }).on('draw.dt',  function() {
    	//解决因滚动条导致的列对不齐问题
        $(".dataTables_scrollBody").css("overflow-y","overlay");
        
        $("#waitVerifyTable").find("th.sorting_asc").removeClass("sorting_asc");
        
//        turn_on_iCheck($("#shippedTab"));
//        $("#chkAllr").on("ifChanged", function() {
//            if ($("#chkAllr").is(":checked")) {
//            	$("#shippedTab").find(".icheck").iCheck("check");
//            } else {
//            	$("#shippedTab").find(".icheck").iCheck("uncheck");
//            }
//        });
    });
}

/**
 * 已完成
 * 
 * @returns
 */
function showCompleteTab() {
    $("#cancelOrder").hide();
    $("#revokeCancelOrder").hide();
    $("#inspectedOrder").hide();
    $("#auditOrder").hide();
    $("#unAuditOrder").hide();
    $("#cancelInspectedOrder").hide();
    $("#finishOrder").hide();
    
    $("#sign").hide();
    $("#batch").hide();
    // 如果已经初期化过，不用重新定义，直接重画表格
    if (complete != null && complete != undefined && "" != complete) {
        complete.draw();
        return;
    }
    complete = $('#completeTable').DataTable({
        "processing" : true,
        "scrollX" : "100%",
        "scrollY" : "410px",
        "scrollCollapse" : false,
        "serverSide" : true,
        "lengthMenu" : [ [ 10, 25, 50, 100, 500, 1000 ], [ 10, 25, 50, 100, 500, 1000 ] ],
        "dom" : '<"bottom"rtflp>',
        "searching" : false,
        "pagingType" : "full_numbers",
        "deferRender" : true,
        "ajax" : {
            "url" : "/order/getCompleteTable.action",
            "data" : function(d) {
                d.quickSearch = quickSearch;
                d.formJson = JSON.stringify(searchCondition);
            }
        },
        "tableTools" : {
            "sRowSelect" : "bootstrap"
        },
        "columns" : [ {
            "data" : "sonShow"
        }, {
            "data" : "chk"
        }, {
            "data" : "sign",
            "render" : function(data, type, row, meta) {
    		       var returnType = "";
    		       var spaceFirst = "&nbsp;&nbsp;";
    		       var centerSpace = "&nbsp;&nbsp;&nbsp;&nbsp;";
    		       var repairSpace = "&nbsp;&nbsp;";
    		       if(row.customerService == ""){
    		    	   if(row.merge == ""){
    		    		   returnType = spaceFirst + data +centerSpace + repairSpace + centerSpace + repairSpace;
    		    	   }else {
    		    		   returnType = spaceFirst + data + centerSpace + repairSpace + centerSpace + row.merge;
    		    	   }
    		       }else{
    		    	   if(row.merge == ""){
    		    		   returnType = spaceFirst + data + centerSpace + row.customerService + centerSpace + repairSpace;
    		    	   }else {
    		    		   returnType = spaceFirst + data + centerSpace + row.customerService + centerSpace + row.merge;
    		    	   }
    		       }
    		       return returnType;
    	        }
        },/* {
            "data" : "customerService"
        }, {
            "data" : "merge"
        },*/ {
            "data" : "ecFlagShow"
        }, {
            "data" : "shopName"
        }, {
            "data" : "buyerNick"
        }, {
            "data" : "tradeCode"
        }, {
            "data" : "orderCode"
        },
        //     {
        //     "data" : "status"
        // },
            {
            "data" : "orderTime"
        }, {
            "data" : "paidDate"
        }, {
            "data" : "custRemark"
        }, {
            "data" : "salesRemark"
        }, {
            "data" : "operation"
        } ],
        "columnDefs" : [ {
            "orderable" : false,
            "targets" : [ 0 ]
        }, {
            "orderable" : false,
            "targets" : [ 1 ]
        }, {
            "orderable" : false,
//            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 2 ]
        },/* {
            "orderable" : false,
            "targets" : [ 3 ]
        }, {
            "orderable" : false,
            "targets" : [ 4 ]
        }, */{
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 3 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 4 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 5 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 6 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 7 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 8 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 9 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 10 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 11 ]
        }
        // , {
        //     "className" : "truncate-text tooltip-column-detail",
        //     "targets" : [ 10 ]
        // }
        ],
        "order" : [ [ 8, "desc" ] ]
    }).on('draw.dt',  function() {
    	//解决因滚动条导致的列对不齐问题
        $(".dataTables_scrollBody").css("overflow-y","overlay");
        
        $("#waitVerifyTable").find("th.sorting_asc").removeClass("sorting_asc");
        
//        turn_on_iCheck($("#completeTab"));
//        $("#chkAllz").on("ifChanged", function() {
//            if ($("#chkAllz").is(":checked")) {
//            	$("#completeTab").find(".icheck").iCheck("check");
//            } else {
//            	$("#completeTab").find(".icheck").iCheck("uncheck");
//            }
//        });
    });
}

/**
 * 已废弃
 * 
 * @returns
 */
function showCancelTab() {
    $("#cancelOrder").hide();
    $("#revokeCancelOrder").show();
    $("#inspectedOrder").hide();
    $("#auditOrder").hide();
    $("#unAuditOrder").hide();
    $("#cancelInspectedOrder").hide();
    $("#finishOrder").hide();
    
    $("#sign").hide();
    $("#batch").hide();
    // 如果已经初期化过，不用重新定义，直接重画表格
    if (cancel != null && cancel != undefined && "" != cancel) {
        cancel.draw();
        return;
    }
    cancel = $('#cancelTable').DataTable({
        "processing" : true,
        "scrollX" : "100%",
        "scrollY" : "410px",
        "scrollCollapse" : false,
        "serverSide" : true,
        "lengthMenu" : [ [ 10, 25, 50, 100, 500, 1000 ], [ 10, 25, 50, 100, 500, 1000 ] ],
        "dom" : '<"bottom"rtflp>',
        "searching" : false,
        "pagingType" : "full_numbers",
        "deferRender" : true,
//        "scrollX" : true,
//        "scrollY" : "410px", 
//        "scrollCollapse" : true,
//        "fixedColumns":   {    
//            "leftColumns": 2,
//            "rightColumns": 1
//                    },

        "ajax" : {
            "url" : "/order/getCancelTable.action",
            "data" : function(d) {
                d.quickSearch = quickSearch;
                d.formJson = JSON.stringify(searchCondition);
            }
        },
        "tableTools" : {
            "sRowSelect" : "bootstrap"
        },
        "columns" : [ {
            "data" : "sonShow"
        }, {
            "data" : "chk"
        }, {
            "data" : "sign",
            "render" : function(data, type, row, meta) {
 		       var returnType = "";
 		       var spaceFirst = "&nbsp;&nbsp;";
 		       var centerSpace = "&nbsp;&nbsp;&nbsp;&nbsp;";
 		       var repairSpace = "&nbsp;&nbsp;";
 		       if(row.customerService == ""){
 		    	   if(row.merge == ""){
 		    		   returnType = spaceFirst + data +centerSpace + repairSpace + centerSpace + repairSpace;
 		    	   }else {
 		    		   returnType = spaceFirst + data + centerSpace + repairSpace + centerSpace + row.merge;
 		    	   }
 		       }else{
 		    	   if(row.merge == ""){
 		    		   returnType = spaceFirst + data + centerSpace + row.customerService + centerSpace + repairSpace;
 		    	   }else {
 		    		   returnType = spaceFirst + data + centerSpace + row.customerService + centerSpace + row.merge;
 		    	   }
 		       }
 		       return returnType;
 	        }
        }, /*{
            "data" : "customerService"
        }, {
            "data" : "merge"
        }, */{
            "data" : "ecFlagShow"
        }, {
            "data" : "shopName"
        }, {
            "data" : "buyerNick"
        }, {
            "data" : "tradeCode"
        }, {
            "data" : "orderCode"
        }, {
            "data" : "status"
        }, {
            "data" : "orderTime"
        }, {
            "data" : "paidDate"
        }, {
            "data" : "custRemark"
        }, {
            "data" : "salesRemark"
        }, {
            "data" : "operation"
        } ],
        "columnDefs" : [ {
            "orderable" : false,
            "targets" : [ 0 ]
        }, {
            "orderable" : false,
            "targets" : [ 1 ]
        }, {
            "orderable" : false,
//            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 2 ]
        }, /*{
            "orderable" : false,
            "targets" : [ 3 ]
        }, {
            "orderable" : false,
            "targets" : [ 4 ]
        } */
        {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 3 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 4 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 5 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 6 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 7 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 8 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 9 ]
        }, {
                "className" : "truncate-text tooltip-column-detail",
                "targets" : [ 10 ]
            }, {
                "className" : "truncate-text tooltip-column-detail",
                "targets" : [ 11 ]
            }, {
                "className" : "truncate-text tooltip-column-detail",
                "targets" : [ 12 ]
            }
        ],
        "order" : [ [ 9, "desc" ] ]
    }).on('draw.dt',  function() {
    	//解决因滚动条导致的列对不齐问题
        $(".dataTables_scrollBody").css("overflow-y","overlay");
        
        $("#waitVerifyTable").find("th.sorting_asc").removeClass("sorting_asc");
        
//        turn_on_iCheck($("#cancelTab"));
//        $("#chkAllcancel").on("ifChanged", function() {
//            if ($("#chkAllcancel").is(":checked")) {
//            	$("#cancelTab").find(".icheck").iCheck("check");
//            } else {
//            	$("#cancelTab").find(".icheck").iCheck("uncheck");
//            }
//        });
    });
}
/**
 * 初始化店铺列表
 * 
 * @returns
 */
function setShopValue() {
    // 初始化店铺列表
    $.ajax({
        type : "GET",
        url : "/shop/unpagedShopList.action?prjId=" + window.top.window.$("#projectSwitch").val(),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false,// 同步
        success : function(data) {
            if (data.result == "success") {
                $("#shopId option").remove();
                $("#shopId").append("<option value=''>请选择</option>");
                $.each(data.data, function(n, value) {
                    $('#shopId').append(
                            "<option value='" + value.shopId + "' shopType = '" + value.shopType + "'>" + value.shopName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}

/**
 * 修改弹出页面
 * @returns
 */
function updateOrder(orderId) {
    frmNewOrderValidate.resetForm();
    $("#frmNewOrder div").removeClass('state-error');
    $("#frmNewOrder div").removeClass('state-success');
    mapOrderSku = {};
    $("#isNew").val("n");
    
    var orderStatus= $("li.active").eq(0).find("a").attr("id");
    
    $("#orderStatus").val(orderStatus);
    $("#orderIdNewOrderPage").val(orderId)
    $("#newOrderPageTitle").html("订单信息修改")
    $('#newOrderTable').dataTable().fnClearTable();
    // 规格新规列表
    if (newOrderTable == null) {
        newOrderTable = $('#newOrderTable').dataTable({
            "bPaginate" : false,
            "bAutoWidth" : true,
//            "bScrollAutoCss" : false, 自动可以表格头和表格对齐
//            "sScrollY" : '160px',     自动可以表格头和表格对齐
            "bSort" : false,
            "searching" : false,
            "bDeferRender" : true,
            "bDestroy" : true,
            "dom" : '<"bottom"rtflp>',
            "columnDefs" : [ {
    	    	"className" : " text-right",
                "targets" : [ 5 ]
            },{
    	    	"className" : " text-right",
                "targets" : [ 6 ]
            },{
    	    	"className" : " text-right",
                "targets" : [ 7 ]
            },{
    	    	"className" : " text-right",
                "targets" : [ 8 ]
            },{
    	    	"className" : " text-right",
                "targets" : [ 9 ]
            },{
    	    	"className" : " text-right",
                "targets" : [ 10 ]
            }]
        });
    }
    
 // 网店 初期化
    $.ajax({
        type : "GET",
        url : "/shop/unpagedShopList.action?prjId=" + window.top.window.$("#projectSwitch").val(),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false,// 同步
        success : function(data) {
            if (data.result == "success") {
                $("#shopIdNew option").remove();
                $("#shopIdNew").append("<option value=''>请选择</option>");
                $.each(data.data, function(n, value) {
                    $('#shopIdNew').append(
                            "<option value='" + value.shopId + "' shopType = '" + value.shopType + "'>" + value.shopName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });

    // 物流公司 初期化
    $.ajax({
        type : "GET",
        url : "/lgst/getLgstByProjectId.action?projectId=" + window.top.window.$("#projectSwitch").val(),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false,// 同步
        success : function(data) {
            if (data.result == "success") {
                $("#lgstIdNew option").remove();
                $("#lgstIdNew").append("<option value=''>请选择</option>");
                $.each(data.data, function(n, value) {
                    $('#lgstIdNew').append("<option value='" + value.lgstId + "'>" + value.lgstName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
    
    $("#orderTypeNew option").remove();
    $("#orderTypeNew").append("<option value=''>请选择</option>");
    $("#orderTypeNew").append("<option value='见面交易'>见面交易</option>");
    $("#orderTypeNew").append("<option value='货到付款'>货到付款</option>");
    $("#orderTypeNew").append("<option value='担保交易'>担保交易</option>");
    $("#orderTypeNew").append("<option value='一口价'>一口价</option>");
    $("#orderTypeNew").append("<option value='先款后货'>先款后货</option>");

    //order
    $.ajax({
        type: "GET",
        url: "/order/getOrderInfo.action?orderId=" + orderId,
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        async: false,//同步
        success: function (data) {
            if (data.result == "success") {
//                $("#orderCode").val(data.data.orderCode);
//                $("#orderCode").attr("title",data.data.orderCode);
                $("#tradeCodeNew").val(data.data.tradeCode);
//                $("#tradeCodeNew").attr("title",data.data.tradeCode);
                $("#shopTypeNew").val(data.data.shopType);
                $("#tradeStatus").val(data.data.tradeStatus);
                //如果是手动的场合
                if ("淘宝"!= data.data.shopType && "京东"!=data.data.shopType){
                    $("#orderTypeNew").val(data.data.orderType);
                } else {
                    $("#orderTypeNew").append("<option value='"+data.data.orderType+"'>"+data.data.orderType+"</option>");
                    $("#orderTypeNew").val(data.data.orderType);
                }
                
                $("#shopIdNew").val(data.data.shopId);

                $.ajax({
                    type: "GET",
                    url: "/stor/getStorageByShopIdNoDelete.action?shopId="+$("#shopIdNew").val(),
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    async: false,//同步
                    success: function (data) {
                        if (data.result == "success") {
                            $("#storIdNew option").remove();
                            $("#storIdNew").append("<option value=''>请选择</option>");
                            $.each(data.data, function (n, value) {
                                $('#storIdNew').append("<option value='" + value.storId +"'>" + value.storName + "</option>");
                            });
                        } else {
                            window.top.window.showModalAlert(data.msg);
                        }
                    },
                    error: function (XMLHttpRequest, textStatus) {
                        if (XMLHttpRequest.status == 500) {
                            var result = eval("(" + XMLHttpRequest.responseText + ")");
                            alert(result.errorObject.errorText);
                        }
                    }
                });
                $("#buyerNickNew").val(data.data.buyerNick);
                $("#storIdNew").val(data.data.storId);
                $("#lgstIdNew").val(data.data.lgstId);
                $("#lgstNoNew").val(data.data.lgstNo);
//                $("#shipTime").val(data.data.shipTime);
//                $("#consignTime").val(data.data.consignTime);
//                if ("y" == data.data.isInvoice) {
//                    $("#isInvoice").attr("checked",true);
//                } else {
//                    $("#isInvoice").attr("checked",false);
//                }
//                if ("y" == data.data.hasInspected) {
//                    $("#hasInspected").attr("checked",true);
//                } else {
//                    $("#hasInspected").attr("checked",false);
//                }
//                $("#invoiceTitle").val(data.data.invoiceTitle);
//                $("#invoiceType").val(data.data.invoiceType);
//                $("#custRemark").val(data.data.custRemark);
//                $("#salesRemark").val(data.data.salesRemark);
                $("#remarkNew").val(data.data.remark);
                $("#consNew").val(data.data.cons);
                $("#consTelNew").val(data.data.consTel);
                $("#consMobileNew").val(data.data.consMobile);
                $("#consAddrNew").val(data.data.consAddr);
                $("#consPostCodeNew").val(data.data.consPostCode);
                if (data.data.provName && data.data.provName!=""){
                    $("#provNameNew").find("option:contains('"+data.data.provName+"')").attr("selected",true);
                    setCitySelectNew();
                }
                if (data.data.cityName && data.data.cityName!=""){
                    $("#cityNameNew").find("option:contains('"+data.data.cityName+"')").attr("selected",true);
                    setDistSelectNew();
                }
                if (data.data.distName && data.data.distName!=""){
                    $("#distNameNew").find("option:contains('"+data.data.distName+"')").attr("selected",true);
                }
                $("#payModeNew").val(data.data.payMode);
                $("#paidFeeNew").val(data.data.paidFee);
                $("#paidDateNew").val(data.data.paidDate);
                $("#lgstFeeNew").val(data.data.lgstFee);
                $("#salesmanNew").val(data.data.salesman);
                
                if ("淘宝"!= data.data.shopType && "京东"!=data.data.shopType){
                    $("form :input") 
                    $('input,textarea',$('form[name="frmNewOrder"]')).attr('readonly',false);
                    $('select',$('form[name="frmNewOrder"]')).removeAttr('disabled');
                    $('select',$('form[name="frmNewOrder"]')).removeAttr('readonly');
                } else {
                    $('input,textarea',$('form[name="frmNewOrder"]')).attr('readonly',false);
                    $('select',$('form[name="frmNewOrder"]')).removeAttr('disabled');
                    $('select',$('form[name="frmNewOrder"]')).removeAttr('readonly');
                    
//                    $("#orderCodeNew").attr('readonly',true);
                    $("#orderTypeNew").attr('readonly',true);
                    $("#buyerNickNew").attr('readonly',true);
                    
                    $("#shopTypeNew").attr('disabled','disabled');
                    $("#shopIdNew").attr('disabled','disabled');
                    
                    $("#orderStatusNew").attr('readonly',true);
                    $("#payModeNew").attr('readonly',true);
                    $("#payModeNew").attr('disabled','disabled');
                    $("#lgstFeeNew").attr('readonly',true);
//                    $("#shipTimeNew").attr('readonly',true);
//                    $("#consignTimeNew").attr('readonly',true);
//                    $("#finishTimeNew").attr('readonly',true);
//                    $("#isInvoiceNew").attr('readonly',true);
//                    $("#invoiceTitleNew").attr('readonly',true);
//                    $("#invoiceTypeNew").attr('readonly',true);
//                    $("#hasInspectedNew").attr('readonly',true);
                }
                $("#tradeCodeNew").attr('readonly',true);
                var tradeStatus = $("#tradeStatus").val();
                if(tradeStatus!='' && tradeStatus!=undefined && tradeStatus!=null){
                    $("#paidFeeNew").attr('readonly',true);
                } else {
                    $("#paidFeeNew").removeAttr("readonly");
                }
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
    
    //ordersku    
    $.ajax({
        type:"GET",
        url:"/order/getOrderSku.action?orderId="+orderId+"&haveVirt=y",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        async: false,//同步
        success:function(data) {
            if (data.result == "success") {
                orderSkuRowIndex = 0;
                //设置规格信息
                $.each(data.data, function (n, value) {
                    var actualCash ="";
                    var discount = "";
                    if (value.qty != '' && value.qty != null && value.qty != undefined && value.factUnitPrice != '' && value.factUnitPrice!=null && value.factUnitPrice!=undefined) {
                        actualCash = value.qty * value.factUnitPrice;
                        discount = (value.salePrice - value.factUnitPrice) * value.qty;
                    }
                    var saleCash = "";
                    if (value.qty != '' && value.qty != null && value.qty != undefined && value.salePrice != '' && value.salePrice!=null && value.salePrice!=undefined) {
                        saleCash = value.salePrice * value.qty;
                    }
                    var deleteButten = "";
                    if (value.deleted=="n"){
                        deleteButten = '<a href="javascript:;" class="deleteU" orderSkuId="'+value.orderSkuId+'" rowIndex ="'+n+'">删除</a>&nbsp;';
                        // 赠品不能执行修改操作
                        if ("赠" != value.skuProperty){
                            deleteButten += '<a href="javascript:;" class="modifyU" orderSkuId="'+value.orderSkuId+'" rowIndex ="'+n+'">修改</a>';
                        }
                    } else {
                        deleteButten = '<a href="javascript:;" class="back" orderskuid="'+value.orderSkuId+'"><font style="color:red">恢复</font></a>';
                        //'<a href="javascript:;" class="deleteU" orderSkuId="'+value.orderSkuId+'" rowIndex ="'+n+'">删除</a>'
                    }
                    
                    newOrderTable.fnAddData([ value.skuProperty, value.goodsCode, value.goodsName, value.skuCode, value.skuName, value.qty, value.salePrice, discount, value.factUnitPrice, saleCash, actualCash, value.remark,
                        deleteButten]);
                    value.goodsId = value.goodsId;
                    value.skuId = value.skuId;
                    GoodsSkuMap[orderSkuRowIndex] = value;
                    orderSkuRowIndex++;
                    
                    if ("赠" == value.skuProperty){
                        mapOrderSku["y:"+value.skuCode] = value.skuCode;
                    } else {
                        mapOrderSku["n:"+value.skuCode] = value.skuCode;
                    }
//                    $("#operStus").val(value.operStus);
                    
//                    $('#createOrderGoods').click(); //增加一个空行
//                    orderTableUpdate.fnUpdate(value.skuProperty, n, 0, false);//属性
//                    orderTableUpdate.fnUpdate(value.ecItemCode, n, 1, false);//平台商品编码
//                    orderTableUpdate.fnUpdate(value.ecItemName, n, 2, false);//平台商品名称
//                    orderTableUpdate.fnUpdate(value.ecSkuCode, n, 3, false);//平台规格编码
//                    orderTableUpdate.fnUpdate(value.ecSkuName, n, 4, false);//平台规格名称
//                    orderTableUpdate.fnUpdate(value.goodsCode, n, 5, false);//商品商家编码
//                    orderTableUpdate.fnUpdate(value.goodsName, n, 6, false);//商品名称
//                    orderTableUpdate.fnUpdate(value.skuCode, n, 7, false);//规格商家编码
//                    orderTableUpdate.fnUpdate(value.skuName, n, 8, false);//规格名称
//                    orderTableUpdate.fnUpdate(value.qty, n, 9, false);//订购数
//                    orderTableUpdate.fnUpdate(value.qty - value.shippingQty - value.shipedQty, n, 10, false);//待发货数 
//                    orderTableUpdate.fnUpdate(value.shippingQty, n, 11, false);//发货中数
//                    orderTableUpdate.fnUpdate(value.shipedQty, n, 12, false);//已发货数
//                    orderTableUpdate.fnUpdate(value.price, n, 13, false);//吊牌价 
//                    orderTableUpdate.fnUpdate(value.goodsSkuCost, n, 14, false);//成本价 
//                    orderTableUpdate.fnUpdate(value.factUnitPrice, n, 15, false);//拍单价  
//                    if (value.divideOrderFee!=null && value.qty!=null && value.divideOrderFee!='' && value.qty!='' && value.divideOrderFee!=undefined && value.qty!=undefined){
//                        orderTableUpdate.fnUpdate(value.divideOrderFee/value.qty, n, 16, false);//实际支付单价  
//                    } else {
//                        orderTableUpdate.fnUpdate(0, n, 16, false);//实际支付单价
//                    }
//                    orderTableUpdate.fnUpdate(value.divideOrderFee, n, 17, false);//实际支付金额
//                    orderTableUpdate.fnUpdate(value.remark, n, 18, false);//备注
//                    
//                    if ($("#operStus").val() == "au"){
//                        orderTableUpdate.fnUpdate('', n, 19, false);
//                    } else {
//                        if ("y" == value.deleted){
//                            if (tab=="waitVerify"){
//                                orderTableUpdate.fnUpdate('<a href="javascript:;" class="back" orderSkuId="'+value.orderSkuId+'" rowIndex ="'+n+'"><font style="color:red">恢复</font></a>', n, 19, false);
//                                $("#btnOrderSkuSave").show();
//                            } else {
//                                orderTableUpdate.fnUpdate('已删除', n, 19, false);
//                                if (tab=="waitAssign"){
//                                    $("#btnOrderSkuSave").show();    
//                                } else {
//                                    $("#btnOrderSkuSave").hide();
//                                }                                 
//                            }
//                        } else {
//                            if (tab=="waitVerify" || tab=="waitAssign"){
//                                orderTableUpdate.fnUpdate('<a href="javascript:;" class="delete" orderSkuId="'+value.orderSkuId+'" rowIndex ="'+n+'">删除</a>', n, 19, false);
//                                $("#btnOrderSkuSave").show();
//                            } else {
//                                orderTableUpdate.fnUpdate('', n, 19, false); 
//                                $("#btnOrderSkuSave").hide();
//                            }
//                        }    
//                    }
//                    
//                    nEditing = null;
//                    map[value.orderSkuId] = value.skuCode+","+value.qty+","+value.factUnitPrice+","+value.remark+","+value.deleted;
//                    orderSkuindex = n;
                    
                });
                $("#newOrderTable").find("tr").each(function () {
                    for(var i=0;i<20;i++){
                        $(this).children('td:eq('+i+')').attr("title", $(this).children('td:eq('+i+')').text());
                    }                      
                });
//                orderSkuindex++;
//                //设置商品分类
//                
//                if ($("#operStus").val() == "au"){
//                    $("#createOrderGoodsGift").hide();
//                    $("#createOrderGoods").hide();
//                    $("#deleteAllOrderGoods").hide();
//                } else {
//                    if ("waitVerify"!=tab){
//                        $("#createOrderGoodsGift").hide();
//                        $("#createOrderGoods").hide();
//                    } else {
//                        $("#createOrderGoodsGift").show();
//                        $("#createOrderGoods").show();
//                    }
//                    
//                    if ("waitVerify"!=tab && "waitAssign"!=tab){
//                        $("#deleteAllOrderGoods").hide();
//                    } else {
//                        $("#deleteAllOrderGoods").show();
//                    }
//                }
                
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error:function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
    
    nEditing = null;

  var editDialog = window.top.window.borrowCustomModalDialog($("#newOrderPage"));
  editDialog.modal({
      show : true,
      backdrop : 'static'
  });
}

//设置输入框和下拉框不可用的title属性
function setInputSelectTitle(){
		var length = window.top.window.$("input").length;
		for(var i=0;i<length;i++){
			if(window.top.window.$("input")[i].disabled || window.top.window.$("input")[i].readOnly){
				window.top.window.$("input")[i].title = window.top.window.$("input")[i].value;
			}
		}
		var sLength = window.top.window.$("select").length;
		for(var i=0;i<sLength;i++){
			if(window.top.window.$("select")[i].disabled){
				var childLength = window.top.window.$("select")[i].children.length;
				for(var j=0;j<childLength;j++){
					if(window.top.window.$("select")[i].children[j].value == window.top.window.$("select")[i].value){
						window.top.window.$("select")[i].title = window.top.window.$("select")[i].children[j].text;
						break;
					}
				}
				
			}
		}
}
/**
 * 弹出新增画面
 * 
 * @returns
 */
function newOrder() {
    mapOrderSku = {};
    orderSkuRowIndex = 0;
    $("#isNew").val("y");
    $("#orderIdNewOrderPage").val("");
    $("#frmNewOrder")[0].reset();
    arrGoodsSku = new Array();
    $("#newOrderPageTitle").html("订单新增");
    $("#goodsCodeList").html("");
    $("#goodsNameList").html("");
    $("#skuCodeList").html("");
    $("#skuNameList").html("");
    frmNewOrderValidate.resetForm();
    $("#frmNewOrder div").removeClass('state-error');
    $("#frmNewOrder div").removeClass('state-success');
    // 按照prjID取得goods，goodsSku
//    $.ajax({
//        type : "GET",
//        url : "/order/getGoodsSku.action",
//        contentType : "application/json;charset=utf-8",
//        dataType : "json",
//        async : false,// 同步
//        success : function(data) {
//            if (data.result == "success") {
//                $.each(data.data, function(n, value) {
//                    var goodsSku = new Object();
//                    goodsSku.goodsType = value.goodsType;
//                    goodsSku.goodsCode = value.goodsCode;
//                    goodsSku.goodsName = value.goodsName;
//                    goodsSku.skuCode = value.skuCode;
//                    goodsSku.skuName = value.skuName;
//                    goodsSku.goodsSkuCount = value.goodsSkuCount;
//                    goodsSku.salePrice = value.salePrice;
//                    goodsSku.discount = value.discount;
//                    goodsSku.actualPrice = value.actualPrice;
//                    goodsSku.saleCash = value.saleCash;
//                    goodsSku.actualCash = value.actualCash;
//                    goodsSku.amount = value.amount;
//                    goodsSku.useCount = value.useCount;
//                    goodsSku.shippingCount = value.shippingCount;
//                    goodsSku.note = value.note;
//                    goodsSku.prjSkuId = value.prjSkuId;
//                    goodsSku.skuId = value.skuId;
//                    goodsSku.goodsId = value.goodsId;
//                    arrGoodsSku.push(goodsSku);
//                    if (value.goodsType == "赠"){
//                        $("#goodsCodeCodeList").append(
//                                '<option label="商品商家编码:' + value.goodsCode + '|商品名称:' + value.goodsName + '|规格商家编码:' + value.skuCode + '|规格名称:'
//                                        + value.skuName + '" value="商品商家编码:' + value.goodsCode + '|序号:' + (n + 1) + '" />');
//                        $("#goodsCodeNameList").append(
//                                '<option label="商品商家编码:' + value.goodsCode + '|商品名称:' + value.goodsName + '|规格商家编码:' + value.skuCode + '|规格名称:'
//                                        + value.skuName + '" value="商品名称:' + value.goodsName + '|序号:' + (n + 1) + '" />');
//                        $("#skuCodeCodeList").append(
//                                '<option label="商品商家编码:' + value.goodsCode + '|商品名称:' + value.goodsName + '|规格商家编码:' + value.skuCode + '|规格名称:'
//                                        + value.skuName + '" value="规格商家编码:' + value.skuCode + '|序号:' + (n + 1) + '" />');
//                        $("#skuCodeNameList").append(
//                                '<option label="商品商家编码:' + value.goodsCode + '|商品名称:' + value.goodsName + '|规格商家编码:' + value.skuCode + '|规格名称:'
//                                        + value.skuName + '" value="规格名称:' + value.skuName + '|序号:' + (n + 1) + '" />');
//                    } else {
//                        $("#goodsCodeList").append(
//                                '<option label="商品商家编码:' + value.goodsCode + '|商品名称:' + value.goodsName + '|规格商家编码:' + value.skuCode + '|规格名称:'
//                                        + value.skuName + '" value="商品商家编码:' + value.goodsCode + '|序号:' + (n + 1) + '" />');
//                        $("#goodsNameList").append(
//                                '<option label="商品商家编码:' + value.goodsCode + '|商品名称:' + value.goodsName + '|规格商家编码:' + value.skuCode + '|规格名称:'
//                                        + value.skuName + '" value="商品名称:' + value.goodsName + '|序号:' + (n + 1) + '" />');
//                        $("#skuCodeList").append(
//                                '<option label="商品商家编码:' + value.goodsCode + '|商品名称:' + value.goodsName + '|规格商家编码:' + value.skuCode + '|规格名称:'
//                                        + value.skuName + '" value="规格商家编码:' + value.skuCode + '|序号:' + (n + 1) + '" />');
//                        $("#skuNameList").append(
//                                '<option label="商品商家编码:' + value.goodsCode + '|商品名称:' + value.goodsName + '|规格商家编码:' + value.skuCode + '|规格名称:'
//                                        + value.skuName + '" value="规格名称:' + value.skuName + '|序号:' + (n + 1) + '" />');
//                    }
//
//                    GoodsSkuMap[n + 1] = goodsSku;
//
//                });
//            } else {
//                window.top.window.showModalAlert(data.msg);
//            }
//        },
//        error : function(XMLHttpRequest, textStatus) {
//            if (XMLHttpRequest.status == 500) {
//                var result = eval("(" + XMLHttpRequest.responseText + ")");
//                alert(result.errorObject.errorText);
//            }
//        }
//    });

    // 网店 初期化
    $.ajax({
        type : "GET",
        url : "/shop/unpagedShopList.action?prjId=" + window.top.window.$("#projectSwitch").val(),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false,// 同步
        success : function(data) {
            if (data.result == "success") {
                $("#shopIdNew option").remove();
                $("#shopIdNew").append("<option value=''>请选择</option>");
                $.each(data.data, function(n, value) {
                    $('#shopIdNew').append(
                            "<option value='" + value.shopId + "' shopType = '" + value.shopType + "'>" + value.shopName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });

    // 物流公司 初期化
    $.ajax({
        type : "GET",
        url : "/lgst/getLgstByProjectId.action?projectId=" + window.top.window.$("#projectSwitch").val(),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false,// 同步
        success : function(data) {
            if (data.result == "success") {
                $("#lgstIdNew option").remove();
                $("#lgstIdNew").append("<option value=''>请选择</option>");
                $.each(data.data, function(n, value) {
                    $('#lgstIdNew').append("<option value='" + value.lgstId + "'>" + value.lgstName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
    
 // 来源单号
    $.ajax({
        type : "GET",
        url : "/order/getTradeCodeNew.action",
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false,// 同步
        success : function(data) {
            if (data.result == "success") {
                $('#tradeCodeNew').val(data.data);
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });

    $('input,textarea',$('form[name="frmNewOrder"]')).attr('readonly',false);
    $('select',$('form[name="frmNewOrder"]')).removeAttr('disabled');
    
//    $("#frmNewOrder")[0].reset();
    $('#newOrderTable').dataTable().fnClearTable();
    // 规格新规列表
    if (newOrderTable == null) {
        newOrderTable = $('#newOrderTable').dataTable({
            "bPaginate" : false,
            "bAutoWidth" : true,
//            "bScrollAutoCss" : false,
//            "sScrollY" : '160px',
            "bSort" : false,
            "searching" : false,
            "bDeferRender" : true,
            "bDestroy" : true,
            "dom" : '<"bottom"rtflp>',
            "columnDefs" : [ {
    	    	"className" : " text-right",
                "targets" : [ 5 ]
            },{
    	    	"className" : " text-right",
                "targets" : [ 6 ]
            },{
    	    	"className" : " text-right",
                "targets" : [ 7 ]
            },{
    	    	"className" : " text-right",
                "targets" : [ 8 ]
            },{
    	    	"className" : " text-right",
                "targets" : [ 9 ]
            },{
    	    	"className" : " text-right",
                "targets" : [ 10 ]
            }]
        });
    }
    nEditing = null;
//    $('#createOrderGoods').click();

    var editDialog = window.top.window.borrowCustomModalDialog($("#newOrderPage"));
    editDialog.modal({
        show : true,
        backdrop : 'static'
    });
}

// 跟新数据到表格上
function saveRow(oTable, nRow) {
    var rInputs = $('input', nRow);
    var aData = oTable.fnGetData(nRow);
    if (rInputs.length <= 0) {
        return;
    }
//    oTable.fnUpdate(rInputs[0].value, nRow, 1, false);// 商品商家编码
//    oTable.fnUpdate(rInputs[1].value, nRow, 2, false);// 商品名称
//    oTable.fnUpdate(rInputs[2].value, nRow, 3, false);// 规格商家编码
//    oTable.fnUpdate(rInputs[3].value, nRow, 4, false);// 规格名称
    oTable.fnUpdate(rInputs[0].value, nRow, 5, false);// 数量
    oTable.fnUpdate(rInputs[1].value, nRow, 8, false);// 实际单价
    oTable.fnUpdate(rInputs[2].value, nRow, 11, false);// 备注
    oTable.fnDraw();
}

// 表格数据变为输入控件
function editRow(oTable, nRow) {
    var aData = oTable.fnGetData(nRow);
    var rTds = $('>td', nRow);
    
//    if (aData[0]=="赠"){
//        rTds[1].innerHTML = '<input type="text" class="form-control input-small getGoodsSku" value="' + aData[1] + '" tableRowIndex="'
//        + nRow.rowIndex + '" list="goodsGiftCodeList">';// 商品商家编码
//rTds[2].innerHTML = '<input type="text" class="form-control input-small getGoodsSku" value="' + aData[2] + '" tableRowIndex="'
//        + nRow.rowIndex + '" list="goodsGiftNameList">';// 商品名称
//rTds[3].innerHTML = '<input type="text" class="form-control input-small getGoodsSku" value="' + aData[3] + '" tableRowIndex="'
//        + nRow.rowIndex + '" list="skuGiftCodeList">';// 规格商家编码
//rTds[4].innerHTML = '<input type="text" class="form-control input-small getGoodsSku" value="' + aData[4] + '" tableRowIndex="'
//        + nRow.rowIndex + '" list="skuGiftNameList">';// 规格名称
//    } else {
//        rTds[1].innerHTML = '<input type="text" class="form-control input-small getGoodsSku" value="' + aData[1] + '" tableRowIndex="'
//        + nRow.rowIndex + '" list="goodsCodeList">';// 商品商家编码
//rTds[2].innerHTML = '<input type="text" class="form-control input-small getGoodsSku" value="' + aData[2] + '" tableRowIndex="'
//        + nRow.rowIndex + '" list="goodsNameList">';// 商品名称
//rTds[3].innerHTML = '<input type="text" class="form-control input-small getGoodsSku" value="' + aData[3] + '" tableRowIndex="'
//        + nRow.rowIndex + '" list="skuCodeList">';// 规格商家编码
//rTds[4].innerHTML = '<input type="text" class="form-control input-small getGoodsSku" value="' + aData[4] + '" tableRowIndex="'
//        + nRow.rowIndex + '" list="skuNameList">';// 规格名称
//    }
    
    rTds[5].innerHTML = '<input type="text" class="form-control input-small getDiscount" value="' + aData[5] + '" tableRowIndex="'
            + nRow.rowIndex + '">';// 数量
    rTds[8].innerHTML = '<input type="text" class="form-control input-small getActualPrice" value="' + aData[8] + '" tableRowIndex="'
            + nRow.rowIndex + '">';// 实际单价
    rTds[11].innerHTML = '<input type="text" class="form-control input-small" value="' + aData[11] + '">';// 备注

    // 输入控件失去焦点画面数据跟新
    window.top.window.$(".getActualPrice").on('blur', function(e) {
        var nRow = window.top.window.$("#newOrderTable tr:nth-child(" + $(this).attr("tableRowIndex") + ")");
//        var index = nRow.find("td")[1].title.split("|");
//        index = index[1].split(":");
//        index = index[1];
//        GoodsSkuMap[index].actualPrice = $(this).val();
        var actualCash = "0";
        var discount = "0";
        if (aData[5] != '' && $(this).val() != '') {
//            GoodsSkuMap[index].actualCash = GoodsSkuMap[index].actualPrice * GoodsSkuMap[index].goodsSkuCount;
//            GoodsSkuMap[index].discount = (GoodsSkuMap[index].salePrice - GoodsSkuMap[index].actualPrice) * GoodsSkuMap[index].goodsSkuCount;
            actualCash = $(this).val() * aData[5];
            discount = (aData[6] - $(this).val()) * aData[5];
        }
//        newOrderTable.fnUpdate(GoodsSkuMap[index].actualPrice, nRow, 8, false);
//        newOrderTable.fnUpdate(GoodsSkuMap[index].actualCash, nRow, 10, false);
//        newOrderTable.fnUpdate(GoodsSkuMap[index].discount, nRow, 7, false);
        newOrderTable.fnUpdate($(this).val(), nRow, 8, false);
        newOrderTable.fnUpdate(actualCash, nRow, 10, false);
        newOrderTable.fnUpdate(discount, nRow, 7, false);
        nEditing = null;
    });

    // 输入控件失去焦点画面数据跟新
    window.top.window.$(".getDiscount").on('blur', function(e) {
//        var nRow = window.top.window.$("#newOrderTable tr:nth-child(" + $(this).attr("tableRowIndex") + ")");
//        var index = nRow.find("td")[1].title.split("|");
//        index = index[1].split(":");
//        index = index[1];
//        GoodsSkuMap[index].goodsSkuCount = $(this).val();
        newOrderTable.fnUpdate($(this).val(), nRow, 5, false);
        // （标准售价-实际单价）*数量
        var actualCash = "0";
        var discount = "0";
        if (aData[8] != '' && $(this).val() != '' && aData[6] != '') {
            discount = (aData[6] - aData[8]) * $(this).val();
        }
        if ($(this).val() != '' && aData[8] != '') {
            actualCash = $(this).val() * aData[8];
        }
        var saleCash = 0;
        if ($(this).val() != '' && aData[6] != '') {
            saleCash = aData[6] * $(this).val();
        }
        newOrderTable.fnUpdate(discount, nRow, 7, false);
        newOrderTable.fnUpdate(saleCash, nRow, 9, false);
        newOrderTable.fnUpdate(actualCash, nRow, 10, false);
        nEditing = null;
    });

    // 输入控件失去焦点画面数据跟新
//    window.top.window.$(".getGoodsSku").on('blur', function(e) {
//        var nRow = window.top.window.$("#newOrderTable tr:nth-child(" + $(this).attr("tableRowIndex") + ")");
//        var index = $(this).val().split("|");
//        index = index[1].split(":");
//        index = index[1];
//        newOrderTable.fnUpdate(GoodsSkuMap[index].goodsType, nRow, 0, false);
//        newOrderTable.fnUpdate("商品商家编码:" + GoodsSkuMap[index].goodsCode + "|序号:" + index, nRow, 1, false);
//        newOrderTable.fnUpdate("商品名称:" + GoodsSkuMap[index].goodsName + "|序号:" + index, nRow, 2, false);
//        newOrderTable.fnUpdate("规格商家编码:" + GoodsSkuMap[index].skuCode + "|序号:" + index, nRow, 3, false);
//        newOrderTable.fnUpdate("规格名称:" + GoodsSkuMap[index].skuName + "|序号:" + index, nRow, 4, false);
//        newOrderTable.fnUpdate(GoodsSkuMap[index].goodsSkuCount, nRow, 5, false);
//        newOrderTable.fnUpdate(GoodsSkuMap[index].salePrice, nRow, 6, false);
//        // （标准售价-实际单价）*数量
//        if (GoodsSkuMap[index].actualPrice != '' && GoodsSkuMap[index].goodsSkuCount != '' && GoodsSkuMap[index].salePrice != '') {
//            GoodsSkuMap[index].discount = (GoodsSkuMap[index].salePrice - GoodsSkuMap[index].actualPrice) * GoodsSkuMap[index].goodsSkuCount;
//        }
//        newOrderTable.fnUpdate(GoodsSkuMap[index].discount, nRow, 7, false);
//        newOrderTable.fnUpdate(GoodsSkuMap[index].actualPrice, nRow, 8, false);
//        if (GoodsSkuMap[index].goodsSkuCount != '' && GoodsSkuMap[index].actualPrice != '') {
//            GoodsSkuMap[index].actualCash = GoodsSkuMap[index].actualPrice * GoodsSkuMap[index].goodsSkuCount;
//        }
//        if (GoodsSkuMap[index].goodsSkuCount != '' && GoodsSkuMap[index].salePrice != '') {
//            GoodsSkuMap[index].saleCash = GoodsSkuMap[index].salePrice * GoodsSkuMap[index].goodsSkuCount;
//        }
//        newOrderTable.fnUpdate(GoodsSkuMap[index].saleCash, nRow, 9, false);
//        newOrderTable.fnUpdate(GoodsSkuMap[index].actualCash, nRow, 10, false);
//        newOrderTable.fnUpdate(GoodsSkuMap[index].note, nRow, 11, false);
//
//        for (var i = 0; i < 15; i++) {
//            nRow.find("td").eq(i).attr("title", nRow.find("td").eq(i).text());
//        }
//        newOrderTable.fnDraw();
//        nEditing = null;
//    });
}

function delOrderGoods(event) {
    if (nEditing !== null && nEditing != event.data.nRow) {
        saveRow(newOrderTable, nEditing);
    }
    var aData = newOrderTable.fnGetData(event.data.nRow);
    
    if(aData[0]!="赠"){
        delete mapOrderSku["n:"+aData[3]];
    } else {
        delete mapOrderSku["y:"+aData[3]];
    }
    
    // 删除数据库存在的数据的时候，需要记录
//    arrOrderGoodsId.push(event.data.orderGoodsId);
    newOrderTable.fnDeleteRow(event.data.nRow);
    newOrderTable.fnDraw();
    nEditing = null;
}

function doAllDelete() {
    // 按照prjID取得goods，goodsSku
    $.ajax({
        type : "GET",
        url : "/order/getGoodsSku.action",
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false,// 同步
        success : function(data) {
            if (data.result == "success") {
                $.each(data.data, function(n, value) {
                    var goodsSku = new Object();
                    goodsSku.goodsType = value.goodsType;
                    goodsSku.goodsCode = value.goodsCode;
                    goodsSku.goodsName = value.goodsName;
                    goodsSku.skuCode = value.skuCode;
                    goodsSku.skuName = value.skuName;
                    goodsSku.goodsSkuCount = value.goodsSkuCount;
                    goodsSku.salePrice = value.salePrice;
                    goodsSku.discount = value.discount;
                    goodsSku.actualPrice = value.actualPrice;
                    goodsSku.saleCash = value.saleCash;
                    goodsSku.actualCash = value.actualCash;
                    goodsSku.amount = value.amount;
                    goodsSku.useCount = value.useCount;
                    goodsSku.shippingCount = value.shippingCount;
                    goodsSku.note = value.note;
                    goodsSku.prjSkuId = value.prjSkuId;
                    arrGoodsSku.push(goodsSku);
                    if (value.goodsType == "赠"){
                        $("#goodsCodeCodeList").append(
                                '<option label="商品商家编码:' + value.goodsCode + '|商品名称:' + value.goodsName + '|规格商家编码:' + value.skuCode + '|规格名称:'
                                        + value.skuName + '" value="商品商家编码:' + value.goodsCode + '|序号:' + (n + 1) + '" />');
                        $("#goodsCodeNameList").append(
                                '<option label="商品商家编码:' + value.goodsCode + '|商品名称:' + value.goodsName + '|规格商家编码:' + value.skuCode + '|规格名称:'
                                        + value.skuName + '" value="商品名称:' + value.goodsName + '|序号:' + (n + 1) + '" />');
                        $("#skuCodeCodeList").append(
                                '<option label="商品商家编码:' + value.goodsCode + '|商品名称:' + value.goodsName + '|规格商家编码:' + value.skuCode + '|规格名称:'
                                        + value.skuName + '" value="规格商家编码:' + value.skuCode + '|序号:' + (n + 1) + '" />');
                        $("#skuCodeNameList").append(
                                '<option label="商品商家编码:' + value.goodsCode + '|商品名称:' + value.goodsName + '|规格商家编码:' + value.skuCode + '|规格名称:'
                                        + value.skuName + '" value="规格名称:' + value.skuName + '|序号:' + (n + 1) + '" />');
                    } else {
                        $("#goodsCodeList").append(
                                '<option label="商品商家编码:' + value.goodsCode + '|商品名称:' + value.goodsName + '|规格商家编码:' + value.skuCode + '|规格名称:'
                                        + value.skuName + '" value="商品商家编码:' + value.goodsCode + '|序号:' + (n + 1) + '" />');
                        $("#goodsNameList").append(
                                '<option label="商品商家编码:' + value.goodsCode + '|商品名称:' + value.goodsName + '|规格商家编码:' + value.skuCode + '|规格名称:'
                                        + value.skuName + '" value="商品名称:' + value.goodsName + '|序号:' + (n + 1) + '" />');
                        $("#skuCodeList").append(
                                '<option label="商品商家编码:' + value.goodsCode + '|商品名称:' + value.goodsName + '|规格商家编码:' + value.skuCode + '|规格名称:'
                                        + value.skuName + '" value="规格商家编码:' + value.skuCode + '|序号:' + (n + 1) + '" />');
                        $("#skuNameList").append(
                                '<option label="商品商家编码:' + value.goodsCode + '|商品名称:' + value.goodsName + '|规格商家编码:' + value.skuCode + '|规格名称:'
                                        + value.skuName + '" value="规格名称:' + value.skuName + '|序号:' + (n + 1) + '" />');
                    }

                    GoodsSkuMap[n + 1] = goodsSku;

                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });

    window.top.window.$('#newOrderTable').dataTable().fnClearTable();
    // 规格新规列表
    newOrderTable = window.top.window.$('#newOrderTable').dataTable({
        "bPaginate" : false,
        "bAutoWidth" : true,
        "bScrollAutoCss" : false,
        "sScrollY" : '160px',
        "bSort" : false,
        "searching" : false,
        "bDeferRender" : true,
        "bDestroy" : true,
        "dom" : '<"bottom"rtflp>',
        "columnDefs" : [ {
	    	"className" : " text-right",
            "targets" : [ 5 ]
        },{
	    	"className" : " text-right",
            "targets" : [ 6 ]
        },{
	    	"className" : " text-right",
            "targets" : [ 7 ]
        },{
	    	"className" : " text-right",
            "targets" : [ 8 ]
        },{
	    	"className" : " text-right",
            "targets" : [ 9 ]
        },{
	    	"className" : " text-right",
            "targets" : [ 10 ]
        }]
    });

    newOrderTable.fnAddData([ '', '', '', '', '', '', '', '', '', '', '', '', '<a href="javascript:;" class="delete" orderGoodsId="">删除</a>' ]);
    newOrderTable.fnDraw();
}

//function refresh() {
//    $("div .active").each(function() {
//        switch ($(this).attr("id")) {
//        case "waitVerifyTab": // 待审核
//            showWaitVerifyTab();
//            break;
//        case "waitAssignTab": // 待分派
//            showWaitAssignTab();
//            break;
//        case "shippingTab": // 发货中
//            showShippingTab();
//            break;
//        case "shippedTab": // 已发货
//            showShippedTab();
//            break;
//        case "completeTab": // 已完成
//            showCompleteTab();
//            break;
//        case "cancelTab": // 已废弃
//            showCancelTab();
//            break;
//        default:
//            break;
//        }
//    });
//    getCounts();
//}

/**
 * 取得tab上面的数字
 * 
 * @returns
 */
function getCounts() {
    var returnValue  = "";
    // 未付款数字,待处理数字,待发货,全部发货,已完成数字,已废弃数字
    $.ajax({
        type : "POST",
        url : "/order/getTabCounts.action?quickSearch=" + quickSearch,
        data : JSON.stringify(searchCondition),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false,// 同步
        success : function(data) {
            if (data.result == "success") {
                $("#waitVerify").html("待审核(" + data.countWaitVerify + ")");
                $("#waitAssign").html("待分派(" + data.countWaitAssign + ")");
                $("#shipping").html("发货中(" + data.countShipping + ")");
                $("#shipped").html("已发货(" + data.countShipped + ")");
                $("#complete").html("已完成(" + data.countComplete + ")");
                $("#cancel").html("已废弃(" + data.countCancel + ")");

                if (data.countWaitVerify!=null && data.countWaitVerify!=undefined && data.countWaitVerify!="" && data.countWaitVerify!=0){
                    returnValue = "showWaitVerifyTab";
                } else if (data.countWaitAssign!=null && data.countWaitAssign!=undefined && data.countWaitAssign!="" && data.countWaitAssign!=0){
                    returnValue = "showWaitAssignTab";
                } else if (data.countShipping!=null && data.countShipping!=undefined && data.countShipping!="" && data.countShipping!=0){
                    returnValue = "showShippingTab";
                } else if (data.countShipped!=null && data.countShipped!=undefined && data.countShipped!="" && data.countShipped!=0){
                    returnValue = "showShippedTab";
                } else if (data.countComplete!=null && data.countComplete!=undefined && data.countComplete!="" && data.countComplete!=0){
                    returnValue = "showCompleteTab";
                } else if (data.countCancel!=null && data.countCancel!=undefined && data.countCancel!="" && data.countCancel!=0){
                    returnValue = "showCancelTab";
                } else {
                    returnValue = "";
                }
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
    return returnValue;
}

/**
 * 废弃订单
 * 
 * @returns
 */
function cancelOrder() {
    var orderArry = new Array();
    $("div .active").each(function() {
        switch ($(this).attr("id")) {
        case "waitVerifyTab": // 待审核
            $('input:checkbox[name=chkOrdera]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "waitAssignTab": // 待分派
            break;
        case "shippingTab": // 发货中
            break;
        case "shippedTab": // 已发货
            break;
        case "completeTab": // 已完成
            break;
        case "cancelTab": // 已废弃
            break;
        default:
            break;
        }
    });
    if (orderArry.length<=0){
        window.top.window.showModalAlert("请选择数据");
        return false;
    }
    
	window.top.window.showModalConfirm("废弃订单系统将无法继续处理，将可能导致漏发，确认废弃吗？", function(){
		$("#cancelRemark").val("");
	    var editDialog = window.top.window.borrowCustomModalDialog($("#modalCancleOrder"));
	    editDialog.modal({
	        show : true,
	        backdrop : 'static'
	    });
	});
}

/**
 * 取消废弃订单
 * 
 * @returns
 */
function revokeCancelOrder() {
    var orderArry = new Array();
    $("div .active").each(function() {
        switch ($(this).attr("id")) {
        case "waitVerifyTab": // 待审核
            break;
        case "waitAssignTab": // 待分派
            break;
        case "shippingTab": // 发货中
            break;
        case "shippedTab": // 已发货
            break;
        case "completeTab": // 已完成
            break;
        case "cancelTab": // 已废弃
            $('input:checkbox[name=chkOrdercancel]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        default:
            break;
        }
    });
    
    if (orderArry.length<=0){
        window.top.window.showModalAlertPretty("请选择数据");
        return false;
    }
    window.top.window.showModalConfirm("确认取消废弃吗？", function(){
    $("#cancelRemark").val("");
        $("#btnRevokeCancelOrder").click();//
        $("#btnRevokeCancel").click();//隐藏弹出层
    });
}

/**
 * 自动
 * 
 * @returns
 */
function onAuto() {
    window.top.window.showModalConfirm("确定设置自动吗？", doOnAuto);
}

function doOnAuto() {
    var orderArry = new Array();

    $("div .active").each(function() {
        switch ($(this).attr("id")) {
        case "waitVerifyTab": // 待审核
            $('input:checkbox[name=chkOrdera]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "waitAssignTab": // 待分派
            break;
        case "shippingTab": // 发货中
            break;
        case "shippedTab": // 已发货
            break;
        case "completeTab": // 已完成
            break;
        case "cancelTab": // 已废弃
            break;
        default:
            break;
        }
    });

    var loading = window.top.window.getIndexBusyOverlay();
    $.ajax({
        type : "POST",
        url : "/order/doOnAuto.action",
        // contentType : "application/json;charset=utf-8",
        // dataType : "json",
        data:{"orderId":orderArry.join(",")},
        //async : true,// 同步
        beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
        success : function(data) {
        	loading.remove();
            if (data.result == "success") {
                
            } else {
                var reg = new RegExp(/\\n/,"g");
//                var errormessage = errormessage.replace(/\n/, "<br/>");
                window.top.window.showModalAlertPretty(data.msg.replace(reg, "<br/>"));
            }
            refresh();
        },
        error : function(XMLHttpRequest, textStatus) {
        	loading.remove();
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
    
    
}

/**
 * 手动
 * 
 * @returns
 */
function offAuto() {
    window.top.window.showModalConfirm("确定设置手动吗？", doOffAuto);
}

function doOffAuto() {
    var orderArry = new Array();
    $("div .active").each(function() {
        switch ($(this).attr("id")) {
        case "waitVerifyTab": // 待审核
            $('input:checkbox[name=chkOrdera]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "waitAssignTab": // 待分派
            $('input:checkbox[name=chkOrderi]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "shippingTab": // 发货中
            $('input:checkbox[name=chkOrderk]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "shippedTab": // 已发货
            break;
        case "completeTab": // 已完成
            break;
        case "cancelTab": // 已废弃
            break;
        default:
            break;
        }
    });

    var loading = window.top.window.getIndexBusyOverlay();
    $.ajax({
        type : "POST",
        url : "/order/doOffAuto.action",
        // contentType : "application/json;charset=utf-8",
        // dataType : "json",
        data:{"orderId":orderArry.join(",")},
        //async : true,// 同步
        beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
        success : function(data) {
        	loading.remove();
            if (data.result == "success") {
                
            } else {
                var reg = new RegExp(/\\n/,"g");
//                var errormessage = errormessage.replace(/\n/, "<br/>");
                window.top.window.showModalAlertPretty(data.msg.replace(reg, "<br/>"));
            }
            refresh();
        },
        error : function(XMLHttpRequest, textStatus) {
        	loading.remove();
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
    
    
}

/**
 * 锁定
 * 
 * @returns
 */
function onLock() {
    window.top.window.showModalConfirm("确定设置锁定吗？", doOnLock);
}

function doOnLock() {
    var orderArry = new Array();

    $("div .active").each(function() {
        switch ($(this).attr("id")) {
        case "waitVerifyTab": // 待审核
            $('input:checkbox[name=chkOrdera]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "waitAssignTab": // 待分派
            $('input:checkbox[name=chkOrderi]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "shippingTab": // 发货中
            $('input:checkbox[name=chkOrderk]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "shippedTab": // 已发货
            break;
        case "completeTab": // 已完成
            break;
        case "cancelTab": // 已废弃
            break;
        default:
            break;
        }
    });

    var loading = window.top.window.getIndexBusyOverlay();
    $.ajax({
        type : "POST",
        url : "/order/doOnLock.action",
        // contentType : "application/json;charset=utf-8",
        // dataType : "json",
        data:{"orderId":orderArry.join(",")},
        //async : true,// 同步
        beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
        success : function(data) {
        	loading.remove();
            if (data.result == "success") {
                
            } else {
                var reg = new RegExp(/\\n/,"g");
//                var errormessage = errormessage.replace(/\n/, "<br/>");
                window.top.window.showModalAlertPretty(data.msg.replace(reg, "<br/>"));
            }
            refresh();
        },
        error : function(XMLHttpRequest, textStatus) {
        	loading.remove();
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
    
    
}

// function offLockCheck(){
// var orderArry = new Array();
// $("div .active").each(function(){
// switch ($(this).attr("id")) {
// case "waitVerifyTab": //待审核
// $('input:checkbox[name=chkOrderk]:checked').each(function(i){
// orderArry.push($(this).attr("orderId"));
// });
// break;
// break;
// case "waitAssignTab": //待分派
// $('input:checkbox[name=chkOrderk]:checked').each(function(i){
// orderArry.push($(this).attr("orderId"));
// });
// break;
// break;
// case "shippingTab": //发货中
// break;
// case "shippedTab": //已发货
// break;
// case "completeTab": //已完成
// break;
// case "cancelTab": //已废弃
// break;
// default:
// break;
// }
// });
//    
// $.ajax({
// type:"POST",
// url:"/order/doCheckOffLock.action?orderId=" + encodeURI(orderArry.join(",")),
// contentType: "application/json;charset=utf-8",
// dataType: "json",
// async: true,//同步
// success:function(data) {
// if (data.result == "success") {
// if (data.msg){
// msg = data.msg.replace(/\n/, "<br/>");
// }
// } else {
// var errormessage = errormessage.replace(/\n/, "<br/>");
// window.top.window.showModalAlertPretty(errormessage);
// }
// },
// error:function(XMLHttpRequest, textStatus) {
// if (XMLHttpRequest.status == 500) {
// var result = eval("(" + XMLHttpRequest.responseText + ")");
// alert(result.errorObject.errorText);
// }
// }
// });
// }
/**
 * 解锁
 * 
 * @returns
 */
function offLock() {
	var lockAlert = false;
	$("div .active").each(function(){
        switch ($(this).attr("id")) {
        case "waitVerifyTab":    //待审核
            $('input:checkbox[name=chkOrdera]:checked').each(function(i){
                
            	var tep = $(this).parent().parent().children('td')[2].children[0].classList[0];
            	if(tep == "badge"){
            		lockAlert = true;
            		return;
            	}
             });
            break;
            break;
        case "waitAssignTab":    //待分派
            $('input:checkbox[name=chkOrderi]:checked').each(function(i){
            	var tep = $(this).parent().parent().children('td')[2].children[0].classList[0];
            	if(tep == "badge"){
            		lockAlert = true;
            		return;
            	}
             });
            break;
            break;
        case "shippingTab":    //发货中
            $('input:checkbox[name=chkOrderk]:checked').each(function(i){
                var tep = $(this).parent().parent().children('td')[2].children[0].classList[0];
                if(tep == "badge"){
                    lockAlert = true;
                    return;
                }
             });
            break;
        case "shippedTab":    //已发货
            break;
        case "completeTab":    //已完成
            break;  
        case "cancelTab":    //已废弃
            break;  
        default:
            break;
        }
    });
	if(!lockAlert){
		var msg = "确定解除锁定吗？";
	    window.top.window.showModalConfirm(msg, doOffLock);
	}else{
		window.top.window.showModalAlert("当前订单为非锁定状态，无需解锁!");
	}
    
}

function doOffLock() {
    orderSplit = "";
    questionOffLock = "1";
    var orderArry =  new Array();
    $("div .active").each(function(){
        switch ($(this).attr("id")) {
        case "waitVerifyTab":    //待审核
            $('input:checkbox[name=chkOrdera]:checked').each(function(i){
                orderArry.push($(this).attr("orderId"));
             });
            break;
            break;
        case "waitAssignTab":    //待分派
            $('input:checkbox[name=chkOrderi]:checked').each(function(i){
                orderArry.push($(this).attr("orderId"));
             });
            break;
            break;
        case "shippingTab":    //发货中
            $('input:checkbox[name=chkOrderk]:checked').each(function(i){
                orderArry.push($(this).attr("orderId"));
             });
            break;
        case "shippedTab":    //已发货
            break;
        case "completeTab":    //已完成
            break;  
        case "cancelTab":    //已废弃
            break;  
        default:
            break;
        }
    });
    orderSplit = (orderArry.join(","));
    question = "1";
    doOffLockDB();
}
var orderSplit = "";
var questionOffLock = "1";
function doOffLockDB() {
    var questionMsg = "test \n";
    var loading = window.top.window.getIndexBusyOverlay();
    $.ajax({
        type:"POST",
        url:"/order/doOffLock.action?question="+question,
        // contentType: "application/json;charset=utf-8",
        // dataType: "json",
        data:{"orderId":orderSplit},
        //async: true,//同步
        beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
        success:function(data) {
        	loading.remove();
            if (data.result == "success") {
                if (data.question!=""){
                    questionMsg = data.question;
                    orderSplit = data.questionId;
                    question = "0";
                    var reg = new RegExp(/\\n/,"g");
                    if (questionMsg!="" && questionMsg!=undefined && questionMsg!=null){                        
                        window.top.window.showModalConfirmsHtml(questionMsg.replace(reg, "<br>"), doOffLockDB);
               		}else{
               			window.top.window.showScoMessage("ok", "解锁成功");
//               			window.top.window.$(".modal-backdrop").removeClass()
               		}
                    window.top.window.$(".modal-backdrop").removeClass()
                } else {
                    
                }
                
            } else {
                var reg = new RegExp(/\\n/,"g");
//              var errormessage = errormessage.replace(/\n/, "<br/>");
              window.top.window.showModalAlertPretty(data.msg.replace(reg, "<br/>"));
            }
            refresh();
        },
        error:function(XMLHttpRequest, textStatus) {
        	loading.remove();
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
    
    
}

/**
 * 验视
 * 
 * @returns
 */
function inspectedOrder() {
    var orderArry = new Array();
    $("div .active").each(function() {
        switch ($(this).attr("id")) {
        case "waitVerifyTab": // 待审核
            $('input:checkbox[name=chkOrdera]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "waitAssignTab": // 待分派
            break;
        case "shippingTab": // 发货中
            break;
        case "shippedTab": // 已发货
            break;
        case "completeTab": // 已完成
            break;
        case "cancelTab": // 已废弃
            break;
        default:
            break;
        }
    });
    if (orderArry.length<=0){
        window.top.window.showModalAlert("请选择数据");
        return false;
    }
    window.top.window.showModalConfirm("确定验视吗？", doInspectedOrder);
}

function doInspectedOrder() {
    var orderArry = new Array();
    $("div .active").each(function() {
        switch ($(this).attr("id")) {
        case "waitVerifyTab": // 待审核
            $('input:checkbox[name=chkOrdera]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "waitAssignTab": // 待分派
            break;
        case "shippingTab": // 发货中
            break;
        case "shippedTab": // 已发货
            break;
        case "completeTab": // 已完成
            break;
        case "cancelTab": // 已废弃
            break;
        default:
            break;
        }
    });

    var loading = window.top.window.getIndexBusyOverlay();
    $.ajax({
        type : "POST",
        url : "/order/inspectedOrder.action",
        // contentType : "application/json;charset=utf-8",
        // dataType : "json",
        data:{"orderId":orderArry.join(",")},
        beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
        success : function(data) {
        	loading.remove();
            if (data.result == "success") {
                if (data.msg){
                    window.top.window.showModalAlert(data.msg);
                }
                refresh();
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
        	loading.remove();
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}

/**
 * 取消验视
 * 
 * @returns
 */
function cancelInspectedOrder() {
    var orderArry = new Array();
    $("div .active").each(function() {
        switch ($(this).attr("id")) {
        case "waitVerifyTab": // 待审核
            $('input:checkbox[name=chkOrdera]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "waitAssignTab": // 待分派
            break;
        case "shippingTab": // 发货中
            break;
        case "shippedTab": // 已发货
            break;
        case "completeTab": // 已完成
            break;
        case "cancelTab": // 已废弃
            break;
        default:
            break;
        }
    });
    if (orderArry.length<=0){
        window.top.window.showModalAlert("请选择数据");
        return false;
    }
    window.top.window.showModalConfirm("确定取消验视吗？", doCancelInspectedOrder);
}

function doCancelInspectedOrder() {
    var orderArry = new Array();
    $("div .active").each(function() {
        switch ($(this).attr("id")) {
        case "waitVerifyTab": // 待审核
            $('input:checkbox[name=chkOrdera]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "waitAssignTab": // 待分派
            break;
        case "shippingTab": // 发货中
            break;
        case "shippedTab": // 已发货
            break;
        case "completeTab": // 已完成
            break;
        case "cancelTab": // 已废弃
            break;
        default:
            break;
        }
    });

    var loading = window.top.window.getIndexBusyOverlay();
    $.ajax({
        type : "POST",
        url : "/order/cancelInspectedOrder.action",
        // contentType : "application/json;charset=utf-8",
        // dataType : "json",
        data:{"orderId":orderArry.join(",")},
        beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
        success : function(data) {
        	loading.remove();
            if (data.result == "success") {
                refresh();
                if (data.msg) {
                    window.top.window.showModalAlert(data.msg);
                }
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
        	loading.remove();
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}

/**
 * 取消审核
 * 
 * @returns
 */
function unAuditOrder() {
    var orderArry = new Array();
    var n = 0;
    $("div .active").each(function() {
        switch ($(this).attr("id")) {
        case "waitVerifyTab": // 待审核
            break;
        case "waitAssignTab": // 待分派
            $('input:checkbox[name=chkOrderi]:checked').each(function(i) {
                n++;
                return false;
            });
            if (n > 0) {
                return false;
            }
            break;
        case "shippingTab": // 发货中
            break;
        case "shippedTab": // 已发货
            break;
        case "completeTab": // 已完成
            break;
        case "cancelTab": // 已废弃
            break;
        default:
            break;
        }
    });
    if (n == 0) {
        window.top.window.showModalAlert("请选择要取消审核的数据");
    } else {
        window.top.window.showModalConfirms("确定取消审核订单吗？", doUnAuditOrder);
    }
}

function doUnAuditOrder() {
    var orderArry = new Array();
    $("div .active").each(function() {
        switch ($(this).attr("id")) {
        case "waitVerifyTab": // 待审核
            break;
        case "waitAssignTab": // 待分派
            $('input:checkbox[name=chkOrderi]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "shippingTab": // 发货中
            break;
        case "shippedTab": // 已发货
            break;
        case "completeTab": // 已完成
            break;
        case "cancelTab": // 已废弃
            break;
        default:
            break;
        }
    });
    ordersIdForAudit = (orderArry.join(","));
    errorMsgForAudit = "";
    
    $.ajax({
        type : "POST",
        url : "/order/unAuditOrder.action",
        // contentType : "application/js
        data:{"orderId":ordersIdForAudit},
        async : false,// 同步
        success : function(data) {

            if (data.result == "success") {
                window.top.window.showModalAlertPretty("取消审核成功");
            } else {
                var reg = new RegExp(/\\n/,"g");
                var errormessage = data.msg.replace(reg, "<br/>");
                window.top.window.showModalAlertPretty("取消审核失败，"+errormessage);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
    refresh();

}

/**
 * 审核
 * 
 * @returns
 */
function auditOrder() {
    var orderArry = new Array();
    var n = 0;
    $("div .active").each(function() {
        switch ($(this).attr("id")) {
        case "waitVerifyTab": // 待审核
            $('input:checkbox[name=chkOrdera]:checked').each(function(i) {
                n++;
                return false;
            });
            if (n > 0) {
                return false;
            }
            break;
        case "waitAssignTab": // 待分派
            break;
        case "shippingTab": // 发货中
            break;
        case "shippedTab": // 已发货
            break;
        case "completeTab": // 已完成
            break;
        case "cancelTab": // 已废弃
            break;
        default:
            break;
        }
    });
    if (n == 0) {
        window.top.window.showModalAlert("请选择要审核的数据");
    } else {
        window.top.window.showModalConfirms("确定审核订单吗？", doAuditOrder);
    }
}

function doAuditOrder() {
    var orderArry = new Array();
    $("div .active").each(function() {
        switch ($(this).attr("id")) {
        case "waitVerifyTab": // 待审核
            $('input:checkbox[name=chkOrdera]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "waitAssignTab": // 待分派
            break;
        case "shippingTab": // 发货中
            break;
        case "shippedTab": // 已发货
            break;
        case "completeTab": // 已完成
            break;
        case "cancelTab": // 已废弃
            break;
        default:
            break;
        }
    });
    ordersIdForAudit = (orderArry.join(","));
    errorMsgForAudit = "";
    auditOrderDB();

}
var ordersIdForAudit = "";
var errorMsgForAudit = "";
var qAuditOrder = "y";
function auditOrderDBQ(){
    qAuditOrder = "n";
    auditOrderDB();
}

function auditOrderDB() {
	var loading = window.top.window.getIndexBusyOverlay();
    $.ajax({
        type : "POST",
        url : "/order/auditOrder.action?msg=" + errorMsgForAudit+"&qAuditOrder="+qAuditOrder,
        // contentType : "application/json;charset=utf-8",
        // dataType : "json",
        data:{"orderId":ordersIdForAudit},
        beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
        success : function(data) {
        	loading.remove();
            if (data.result == "success") {
                // window.top.window.showModalConfirms("aaaaa？", doAuditOrder);
                if (data.confirmMsg) {
                    var orderArry = new Array();
                    $.each(data.data, function(n, value) {
                        orderArry.push(value);
                    });
                    ordersIdForAudit = (orderArry.join(","));
                    var errormessage = data.msg.replace(/\n/, "<br/>");
                    //替换\n
                    var reg = new RegExp(/\\n/,"g");
                    var confirmMsg = "";
                    confirmMsg = data.confirmMsg
                    confirmMsg = confirmMsg.replace(reg, "<br/>");
                    
                    errorMsgForAudit = errormessage;
                    window.top.window.showModalConfirmsHtml(confirmMsg, auditOrderDBQ);
                } else {
                    if (data.msg) {
                    	var errormessage = "";
                    	errormessage = data.msg;
                    	var reg = new RegExp(/\\n/,"g");
                        errormessage = errormessage.replace(reg, "<br/>");
                        window.top.window.showModalAlertPretty(errormessage);
                    } else {
                        window.top.window.showModalAlert("审核成功");
                        // 调用列表
                        refresh();
                    }
                }
            } else {
                // window.top.window.showModalConfirms("bbbb？", doAuditOrder);
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
        	loading.remove();
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
    refresh();
    
}
/**
 * 取消合并订单
 * 
 * @param id
 * @returns
 */
function cancelMerger(id) {
    window.top.window.$("#modalConfirmContent").text("确定取消合并订单吗?");
    window.top.window.$('#btnModalOK').unbind();
    window.top.window.$("#btnModalOK").on('click', '', {
        id : id
    }, doCancelMerger);
    window.top.window.$('#modal-confirm').modal({
        show : true,
        backdrop : 'static'
    });
}
function doCancelMerger(event) {
    $.ajax({
        type : "POST",
        url : "/order/cancelMerger.action?orderId=" + encodeURI(event.data.id),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : true,// 同步
        success : function(data) {
            if (data.result == "success") {
                if (data.msg) {
                    var reg = new RegExp(/\\n/,"g");
                    var errormessage = data.msg.replace(reg, "<br/>");
                    window.top.window.showModalAlertPretty(errormessage);
                } else {
                    window.top.window.showModalAlertPretty("取消合并订单成功");
                    refresh();
                }

            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}
/**
 * 分派
 * 
 * @param id
 * @returns
 */
function assignorder(id, btn) {
    // 物流公司 初期化
    $.ajax({
        type : "GET",
        url : "/lgst/getLgstByProjectId.action?projectId=" + window.top.window.$("#projectSwitch").val(),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false,// 同步
        success : function(data) {
            if (data.result == "success") {
                $("#lgstIdShipAssign option").remove();
                $("#lgstIdShipAssign").append("<option value=''>请选择</option>");
                $.each(data.data, function(n, value) {
                    $('#lgstIdShipAssign').append(
                            "<option value='" + value.lgstId + "' lgstCode='" + value.lgstCode + "'>" + value.lgstName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });

    // 订单画面信息设置
    $.ajax({
        type : "GET",
        url : "/order/getOrderInfo.action?orderId=" + encodeURI(id),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false,// 同步
        success : function(data) {
            if (data.result == "success") {
                $("#orderCodeAssign").html("订单编号：" + (data.data.orderCode!=null?data.data.orderCode:""));
                $("#orderStatusAssign").html("订单状态：" + (data.data.status!=null?data.data.status:""));
                $("#orderTypeAssign").html("订单类型：" + (data.data.orderType!=null?data.data.orderType:""));
                $("#payModeAssign").html("支付方式：" + (data.data.payMode!=null?data.data.payMode:""));
                $("#shopTypeAssign").html("订单来源：" + (data.data.shopType!=null?data.data.shopType:""));
                $("#shopNameAssign").html("来源网店：" + (data.data.shopName!=null?data.data.shopName:""));
                $("#tradeCodeAssign").html("来源单号：" + (data.data.tradeCode!=null?data.data.tradeCode:""));
                $("#buyerNickAssign").html("客户ID：" + (data.data.buyerNick!=null?data.data.buyerNick:""));
                $("#shipTimeAssign").html("发货日期：" + (data.data.shipTime!=null?data.data.shipTime:""));
                $("#storNameAssign").html("发货仓库：" + (data.data.storName!=null?data.data.storName:""));
                $("#lgstNameAssign").html("物流公司：" + (data.data.lgstName!=null?data.data.lgstName:""));
                $("#lgstNoAssign").html("物流单号：" + (data.data.lgstNo!=null?data.data.lgstNo:""));
                $("#custRemarkAssign").html("买家留言：" + (data.data.custRemark!=null?data.data.custRemark:""));
                $("#salesRemarkAssign").html("卖家备注：" + (data.data.salesRemark!=null?data.data.salesRemark:""));
                $("#remarkAssign").html("内部备注：" + (data.data.remark!=null?data.data.remark:""));

                $("#consAssign").val(data.data.cons);
                $("#consTelAssign").val(data.data.consTel);
                $("#consMobileAssign").val(data.data.consMobile);
                $("#consAddrAssign").val(data.data.consAddr);
                $("#consPostCode").val(data.data.consPostCode);

                if (data.data.provName!="" && data.data.provName!=null && data.data.provName!=undefined){
                    $("#provNameAssign").find("option:contains('" + data.data.provName + "')").attr("selected", true);
                    setCitySelect();
                }
                if (data.data.cityName!="" && data.data.cityName!=null && data.data.cityName!=undefined){
                    $("#cityNameAssign").find("option:contains('" + data.data.cityName + "')").attr("selected", true);
                    setDistSelect();
                }
                if (data.data.distName!="" && data.data.distName!=null && data.data.distName!=undefined){
                    $("#distNameAssign").find("option:contains('" + data.data.distName + "')").attr("selected", true);
                }

                $("#lgstIdShipAssign").val(data.data.lgstId);

                $.ajax({
                    type : "GET",
                    url : "/stor/getStorageByShopIdNoDelete.action?shopId=" + data.data.shopId,
                    contentType : "application/json;charset=utf-8",
                    dataType : "json",
                    async : false,// 同步
                    success : function(data) {
                        if (data.result == "success") {
                            $("#storIdShipAssign option").remove();
                            $("#storIdShipAssign").append("<option value=''>请选择</option>");
                            $.each(data.data, function(n, value) {
                                $('#storIdShipAssign')
                                        .append(
                                                "<option value='" + value.storId + "' storCode='" + value.storCode + "'>" + value.storName
                                                        + "</option>");
                            });
                        } else {
                            window.top.window.showModalAlert(data.msg);
                        }
                    },
                    error : function(XMLHttpRequest, textStatus) {
                        if (XMLHttpRequest.status == 500) {
                            var result = eval("(" + XMLHttpRequest.responseText + ")");
                            alert(result.errorObject.errorText);
                        }
                    }
                });
                $('#storIdShipAssign').val(data.data.storId);

            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });

    // 发货画面信息设置
    $('#shipOrderTable').dataTable().fnClearTable();
    // 规格新规列表
    shipOrderTable = $('#shipOrderTable').dataTable({
        "bPaginate" : false,
//        "bAutoWidth" : true,
//        "bScrollAutoCss" : false,
//        "sScrollY" : '200px',
//        "bSort" : false,
//        "sScrollX": "100%",
//        "sScrollXInner": "110%",
//        "bScrollCollapse": true,
        "searching" : false,
        "bDeferRender" : true,
        "bDestroy" : true,
        "ordering": false,
        "dom" : '<"bottom"rtflp>',
        "columnDefs" : [ {
	    	"className" : " text-right",
            "targets" : [ 9 ]
        },{
	    	"className" : " text-right",
            "targets" : [ 10 ]
        },{
	    	"className" : " text-right",
            "targets" : [ 11 ]
        },{
	    	"className" : " text-right",
            "targets" : [ 12 ]
        },{
	    	"className" : " text-right",
            "targets" : [ 13 ]
        },{
	    	"className" : " text-right",
            "targets" : [ 14 ]
        },{
	    	"className" : " text-right",
            "targets" : [ 15 ]
        }]
    });
    nEditingshipOrder = null;
    $.ajax({
        type : "GET",
        url : "/order/getOrderSku.action?orderId=" + id + "&haveVirt=n",
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false,// 同步
        success : function(data) {
            if (data.result == "success") {
                var tab = $('#tab', window.parent.document).val();
                // 设置规格信息
                var flg = '0';
                var rowN = "0";
                $.each(data.data, function(n, value) {
                    if (value.deleted!="y"){
                        newShipOrderTableRow(); // 增加一个空行
                        shipOrderTable.fnUpdate(value.skuProperty, rowN, 0, false);// 属性
                        shipOrderTable.fnUpdate(value.ecItemOuterCode, rowN, 1, false);// 平台商品编码
                        shipOrderTable.fnUpdate(value.ecItemName, rowN, 2, false);// 平台商品名称
                        shipOrderTable.fnUpdate(value.ecSkuOuterCode, rowN, 3, false);// 平台规格编码
                        shipOrderTable.fnUpdate(value.ecSkuName, rowN, 4, false);// 平台规格名称
                        shipOrderTable.fnUpdate(value.goodsCode, rowN, 5, false);// 商品商家编码
                        shipOrderTable.fnUpdate(value.goodsName, rowN, 6, false);// 商品名称
                        shipOrderTable.fnUpdate(value.skuCode, rowN, 7, false);// 规格商家编码
                        shipOrderTable.fnUpdate(value.skuName, rowN, 8, false);// 规格名称
                        shipOrderTable.fnUpdate(value.salePrice, rowN, 9, false);// 标准单价
                        shipOrderTable.fnUpdate(value.factUnitPrice, rowN, 10, false);// 实际单价
                        shipOrderTable.fnUpdate(value.qty, rowN, 11, false);// 订购数
                        shipOrderTable.fnUpdate(value.qty - value.shippingQty - value.shipedQty, rowN, 12, false);// 待发货数
                        shipOrderTable.fnUpdate(value.shippingQty, rowN, 13, false);// 发货中数
                        shipOrderTable.fnUpdate(value.shipedQty, rowN, 14, false);// 已发货数
                        shipOrderTable.fnUpdate("", rowN, 15, false);
                        if (value.skuProperty=="虚" || value.deleted=="y"){
                            shipOrderTable.fnUpdate('', rowN, 16, false);
                        } else {
                            flg = '1';
                            shipOrderTable.fnUpdate('<a href="javascript:;" class="edit" orderSkuId="' + value.orderSkuId + '" rowIndex="' + rowN
                                    + '">编辑</a>', rowN, 16, false);    
                        }
                        
                        nEditingshipOrder = null;
                        orderSkuIndex = n;
                        rowN++;
                    }
                });
                
                if (flg=='0'){
                    $("#btnAssignAdd").hide();
                } else {
                    $("#btnAssignAdd").show();
                }
                
                $("#shipOrderTable").find("tr").each(function() {
                    for (var i = 0; i < 20; i++) {
                        $(this).children('td:eq(' + i + ')').attr("title", $(this).children('td:eq(' + i + ')').text());
                    }
                });
                orderSkuIndex++;
                // 设置商品分类

            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
    
    $("#btnAssignAdd").attr("orderId",id);
    var editDialog = window.top.window.borrowCustomModalDialog($("#assignOrderPage"));
    editDialog.modal({
        show : true,
        backdrop : 'static'
    });
    // window.top.window.$("#modalConfirmContent").text("确定分派该订单吗?");
    // window.top.window.$('#btnModalOK').unbind();
    // window.top.window.$("#btnModalOK").on('click', '',{id:id},
    // doAssignorder);
    // window.top.window.$('#modal-confirm').modal({show:true,
    // backdrop:'static'});
}

function doAssignorder() { 
    var assigObject = new Object();
    var shiporder = new Object();
    var arrSku = new Array();
    // 父窗体归还本页的编辑对话框
    window.top.window.returnCustomModalDialog();

    // 表值同步
    if (nEditingshipOrder != null) {
        saveshipOrderRow(shipOrderTable, nEditingshipOrder);
    }
    nEditingshipOrder = null;

    $('#shipOrderTable tbody tr').each(function() {
        var sku = new Object();
        var aData = shipOrderTable.fnGetData(this);
        var temp = aData[16].split("orderSkuId=");
        var orderSkuId = temp[1].split(" rowIndex", 1);

        if (aData[15] != "" && aData[15] != undefined && aData[15] != null) {
            sku.orderSkuId = orderSkuId[0].replace("\"","").replace("\"","");
            sku.addShippingQty = aData[15];
            arrSku.push(sku);
        }

    });

    if (arrSku.length <= 0) {
        window.top.window.showModalAlert("没有可分派的数据");
        window.top.window.borrowCustomModalDialog($("#assignOrderPage"));
    } else {
        assigObject.arrSku = arrSku;
        shiporder.cons = $("#consAssign").val();
        shiporder.consTel = $("#consTelAssign").val();
        shiporder.consMobile = $("#consMobileAssign").val();
        shiporder.consAddr = $("#consAddrAssign").val();
        // skuObject.consPostCode = $("#consPostCodeAssign").val();
        if ($("#provNameAssign").val() != '') {
            shiporder.provName = $("#provNameAssign").find("option:selected").text();
            shiporder.areaCoding = $("#provNameAssign").val();
        }
        if ($("#cityNameAssign").val() != '') {
            shiporder.cityName = $("#cityNameAssign").find("option:selected").text();
            shiporder.areaCoding = $("#cityNameAssign").val();
        }
        if ($("#distNameAssign").val() != '') {
            shiporder.distName = $("#distNameAssign").find("option:selected").text();
            shiporder.areaCoding = $("#distNameAssign").val();
        }
        if ($("#storIdShipAssign").val() != '') {
            shiporder.storId = $("#storIdShipAssign").val();
            shiporder.storName = $("#storIdShipAssign").find("option:selected").text();
            shiporder.storCode = $("#storIdShipAssign").find("option:selected").attr("storCode");
        }
        if ($("#lgstIdShipAssign").val() != '') {
            shiporder.lgstId = $("#lgstIdShipAssign").val();
            shiporder.lgstName = $("#lgstIdShipAssign").find("option:selected").text();
            shiporder.lgstCode = $("#lgstIdShipAssign").find("option:selected").attr("lgstCode");
        }
        assigObject.shiporder = shiporder;
        assigObject.orderId = orderIdAssign;
        assigObject.emptyLgstCompany = emptyLgstCompany;
        assigObject.hasrefund = hasrefund;
        
        //分派订单
        $.ajax({
            type : "POST",
            url : "/order/assignOrder.action",
            data : JSON.stringify(assigObject),
            contentType : "application/json;charset=utf-8",
            dataType : "json",
            async : true, // 同步
            success : function(data) {
                if (data.result == "y") {
                    window.top.window.showModalAlert("保存成功");
                    $('#assignOrderPage').modal('hide');
                } else {
                    window.top.window.borrowCustomModalDialog($("#assignOrderPage"));
                    if (data.msg!="" && data.msg!=null && data.msg!=undefined){
                        window.top.window.showModalAlert(data.msg);    
                    } else {
                        if (data.questionLgstId!="" && data.questionLgstId!=null && data.questionLgstId!=undefined){
                            window.top.window.showModalConfirms(data.questionLgstId, doAssignNoLgstId);    
                        } else if (data.questionhasrefund!="" && data.questionhasrefund!=undefined){
                            window.top.window.showModalConfirms(data.questionhasrefund, doAssignHasrefund);
                        }
                    }
                }
                refresh();
            },
            error : function(XMLHttpRequest, textStatus) {
                if (XMLHttpRequest.status == 500) {
                    var result = eval("(" + XMLHttpRequest.responseText + ")");
                    alert(result.errorObject.errorText);
                }
            }
        });
    }
}
function doAssignNoLgstId(){
    emptyLgstCompany = "n";
    doAssignorder();
}
function doAssignHasrefund(){
    hasrefund = "n";
    doAssignorder()
}

function newShipOrderTableRow() {
    shipOrderTable.fnAddData([ '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
            '<a href="javascript:;" class="edit" orderSkuId="" rowIndex="' + orderSkuIndex + '">编辑</a>' ])
    shipOrderTable.fnDraw();
}

function editshipOrderRow(oTable, nRow) {
    var aData = oTable.fnGetData(nRow);
    var temp = aData[16].split("orderSkuId=");
    var orderSkuId = temp[1].split(" rowIndex", 1);
    orderSkuId = orderSkuId.toString().replace(/\"/g, "");
    var rTds = $('>td', nRow);
    rTds[15].innerHTML = '<input type="text" class="form-control input-small getActualPriceForTab" value="' + aData[15] + '" tableRowIndex="'
            + nRow.rowIndex + '">';// 发货数量
    rTds[16].innerHTML = aData[16].replace("编辑", "保存");
}

// 跟新数据到表格上
function saveshipOrderRow(oTable, nRow) {
    var rInputs = $('input', nRow);
    var aData = oTable.fnGetData(nRow);
    oTable.fnUpdate(rInputs[0].value, nRow, 15, false);// 发货数量
    oTable.fnDraw();
}

function rollbackRowshipOrder(oTable, nRow) {
    var aData = oTable.fnGetData(nRow);
    var rTds = $('>td', nRow);
    for (var i = 0, iLen = rTds.length; i < iLen; i++) {
        oTable.fnUpdate(aData[i], nRow, i, false);
    }
    oTable.fnDraw();
}

/**
 * 系统订单完成
 * 
 * @returns
 */
function finishOrder() {
    var orderArry = new Array();
    $("div .active").each(function() {
        switch ($(this).attr("id")) {
        case "waitVerifyTab": // 待审核
            break;
        case "waitAssignTab": // 待分派
            $('input:checkbox[name=chkOrderi]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "shippingTab": // 发货中
            $('input:checkbox[name=chkOrderk]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "shippedTab": // 已发货
            $('input:checkbox[name=chkOrderr]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "completeTab": // 已完成
            break;
        case "cancelTab": // 已废弃
            break;
        default:
            break;
        }
    });

    if (orderArry.length<=0){
        window.top.window.showModalAlertPretty("请选择数据");
        return false;
    }
    window.top.window.showModalConfirm("确定完成订单吗？", doFinishOrder);
}

function doFinishOrder() {
    var orderArry = new Array();
    $("div .active").each(function() {
        switch ($(this).attr("id")) {
        case "waitVerifyTab": // 待审核
            break;
        case "waitAssignTab": // 待分派
            $('input:checkbox[name=chkOrderi]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "shippingTab": // 发货中
            $('input:checkbox[name=chkOrderk]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "shippedTab": // 已发货
            $('input:checkbox[name=chkOrderr]:checked').each(function(i) {
                orderArry.push($(this).attr("orderId"));
            });
            break;
        case "completeTab": // 已完成
            break;
        case "cancelTab": // 已废弃
            break;
        default:
            break;
        }
    });

    $.ajax({
        type : "POST",
        url : "/order/finishOrder.action",
        // contentType : "application/json;charset=utf-8",
        // dataType : "json",
        data:{"orderId":orderArry.join(",")},
        async : true,// 同步
        success : function(data) {
            if (data.result == "success") {
                if (data.msg) {
                    window.top.window.showModalAlertPretty(data.msg);
                }
                refresh();
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}

/**
 * 批量备注
 *
 * @returns
 */
function bachSetRemark() {
    var orderArry = new Array();
    //
    var remark = "";
    var n = 0;
    $("div .active").each(function () {
        switch ($(this).attr("id")) {
            case "waitVerifyTab": // 待审核
                $('input:checkbox[name=chkOrdera]:checked').each(function (i) {
                    if (n == 0) {
                        remark = $(this).attr("remark");
                    } else {
                        remark = "";
                        return false;
                    }
                    n++;
                });
                break;
            case "waitAssignTab": // 待分派
                $('input:checkbox[name=chkOrderi]:checked').each(function (i) {
                    if (n == 0) {
                        remark = $(this).attr("remark");
                    } else {
                        remark = "";
                        return false;
                    }
                    n++;
                });
                break;
            case "shippingTab": // 发货中
                $('input:checkbox[name=chkOrderk]:checked').each(function (i) {
                    if (n == 0) {
                        remark = $(this).attr("remark");
                    } else {
                        remark = "";
                        return false;
                    }
                    n++;
                });
                break;
            case "shippedTab": // 已发货
                $('input:checkbox[name=chkOrderr]:checked').each(function (i) {
                    if (n == 0) {
                        remark = $(this).attr("remark");
                    } else {
                        remark = "";
                        return false;
                    }
                    n++;
                });
                break;
            case "completeTab": // 已完成
                break;
            case "cancelTab": // 已废弃
                break;
            default:
                break;
        }
    });

    if (n == 0) {
        window.top.window.showModalAlert("请选择要批量设置的数据");
        return;
    }

    $("#addRemark").val(remark);
    var editDialog = window.top.window.borrowCustomModalDialog($("#modalBatchRemark"));
    editDialog.modal({
        show: true,
        backdrop: 'static'
    });
}

/**
 * 批量仓库
 * 
 * @returns
 */
var shopId = "";
function bachSetStor() {
    var orderArry = new Array();
    var remark = "";
    var n = 0;
    var flgdifferentShop =  "0";
    $("div .active").each(function() {
        switch ($(this).attr("id")) {
        case "waitVerifyTab": // 待审核
            $('input:checkbox[name=chkOrdera]:checked').each(function(i) {
                if (n==0){
                    shopId = $(this).attr("shopId");
                    n++;
                } else {
                    if (shopId!=$(this).attr("shopId")){
                        flgdifferentShop = "1";
                        n++;
                        return false;
                    }
                }
            });
            break;
        case "waitAssignTab": // 待分派
            $('input:checkbox[name=chkOrderi]:checked').each(function(i) {
                if (n==0){
                    shopId = $(this).attr("shopId");
                    n++;
                } else {
                    if (shopId!=$(this).attr("shopId")){
                        flgdifferentShop = "1";
                        n++;
                        return false;
                    }
                }
            });
            break;
        case "shippingTab": // 发货中
            break;
        case "shippedTab": // 已发货
            break;
        case "completeTab": // 已完成
            break;
        case "cancelTab": // 已废弃
            break;
        default:
            break;
        }
    });

    if (flgdifferentShop=="1"){
        window.top.window.showModalAlert("不同的店铺不能批量设置仓库");
        return;
    }
    if (n == 0) {
        window.top.window.showModalAlert("请选择要批量设置的数据");
        return;
    }

    // 设置列表
    if (selectStorTable!=null){
        selectStorTable.draw();
    } else {
        selectStorTable = $('#selectStorTable').DataTable({
            "bPaginate": false,
            "processing" : true,
            "serverSide" : true,
            "dom" : '<"bottom"rtfli>',
            "searching" : false,
            "deferRender" : true,
            "info": false,
            "ajax" : {
                "url" : "/stor/getStorageByShopIdNoDelete.action",
                "data" : function(d) {
                    d.shopId = shopId;
                }
            },
            "tableTools" : {
                "sRowSelect" : "bootstrap"
            },
            "columns" : [ {
                "data" : "storName"
            }, {
                "data" : "operation"
            } ],
            "columnDefs" : [ {
                "orderable" : false,
                "targets" : [ 1 ]
            } ],
            "order" : [ [ 0, "asc" ] ]
        });
    }
    var editDialog = window.top.window.borrowCustomModalDialog($("#modalBatchStor"));
    editDialog.modal({
        show : true,
        backdrop : 'static'
    });
}

/**
 * 批量设置仓库（选择仓库）
 * 
 * @param id
 * @param name
 * @param btn
 * @returns
 */
function selectStor(id, name,code, btn) {
    var xval = window.top.window.getIndexBusyOverlay();
    if(xval) {
        xval.settext("正在处理中，请稍后...");
    }

    setTimeout(function(){
        var orderArry = new Array();
        $("div .active").each(function() {
            switch ($(this).attr("id")) {
                case "waitVerifyTab": // 待审核
                    $('input:checkbox[name=chkOrdera]:checked').each(function(i) {
                        orderArry.push($(this).attr("orderId"));
                    });
                    break;
                case "waitAssignTab": // 待分派
                    $('input:checkbox[name=chkOrderi]:checked').each(function(i) {
                        orderArry.push($(this).attr("orderId"));
                    });
                    break;
                case "shippingTab": // 发货中
                    break;
                case "shippedTab": // 已发货
                    break;
                case "completeTab": // 已完成
                    break;
                case "cancelTab": // 已废弃
                    break;
                default:
                    break;
            }
        });

        $.ajax({
            type : "POST",
            url : "/order/batchUpdateShipmentWarehouse.action?"+ "storId="+id+"&storName="+name+"&storCode="+code ,
            // contentType : "application/json;charset=utf-8",
            // dataType : "json",
            data:{"orderId":orderArry.join(",")},
            //async : false,// 同步
            success : function(data) {
                xval.remove();
                // 父窗体归还本页的编辑对话框
                window.top.window.returnCustomModalDialog();
                if (data.result == "success") {
                    if (data.msg) {
                        window.top.window.showModalAlert(data.msg);
                    } else {
                        window.top.window.showModalAlert("批量设置发货仓库成功");
                    }
                    $("#btnReturnBatch").click();
                } else {
                    window.top.window.showModalAlert(data.msg);
                    window.top.window.borrowCustomModalDialog($("#modalBatchStor"));
                }
            },
            error : function(XMLHttpRequest, textStatus) {
            	xval.remove();
                if (XMLHttpRequest.status == 500) {
                    var result = eval("(" + XMLHttpRequest.responseText + ")");
                    alert(result.errorObject.errorText);
                }
            }
        });
    },0);
}

/**
 * 批量物流公司
 * 
 * @returns
 */
function bachSetLgst() {
    var orderArry = new Array();
    var remark = "";
    var n = 0;
    $("div .active").each(function() {
        switch ($(this).attr("id")) {
        case "waitVerifyTab": // 待审核
            $('input:checkbox[name=chkOrdera]:checked').each(function(i) {
                n++;
                return false;
            });
            break;
        case "waitAssignTab": // 待分派
            $('input:checkbox[name=chkOrderi]:checked').each(function(i) {
                n++;
                return false;
            });
            break;
        case "shippingTab": // 发货中
            break;
        case "shippedTab": // 已发货
            break;
        case "completeTab": // 已完成
            break;
        case "cancelTab": // 已废弃
            break;
        default:
            break;
        }
    });

    if (n == 0) {
        window.top.window.showModalAlert("请选择要批量设置的数据");
        return;
    }

    // 设置列表
    if (selectLgstTable!=null){
        selectLgstTable.draw();
    } else {
        selectLgstTable = $('#selectLgstTable').DataTable({
            "processing" : true,
            "serverSide" : true,
            "lengthMenu" : [ [ 10, 25, 50, -1 ], [ 10, 25, 50, "All" ] ],
            "dom" : '<"bottom"rtflp>',
            "searching" : false,
            "pagingType" : "full_numbers",
            "deferRender" : true,
            "ajax" : {
                "url" : "/lgst/getLgstByProjectId.action?projectId=" + window.top.window.$("#projectSwitch").val(),
            },
            "tableTools" : {
                "sRowSelect" : "bootstrap"
            },
            "columns" : [ {
                "data" : "lgstName"
            }, {
                "data" : "operation"
            } ],
            "columnDefs" : [ {
                "orderable" : false,
                "targets" : [ 1 ]
            } ],
            "order" : [ [ 0, "asc" ] ]
        });
    }
    

    var editDialog = window.top.window.borrowCustomModalDialog($("#modalBatchLgst"));
    editDialog.modal({
        show : true,
        backdrop : 'static'
    });
}

/**
 * 批量设置物流公司（选择物流公司）
 * 
 * @param id
 * @param name
 * @param btn
 * @returns
 */
function selectLgst(id, name, code, btn) {
    // // 父窗体归还本页的编辑对话框
    // window.top.window.returnCustomModalDialog();
    var xval = window.top.window.getIndexBusyOverlay();
    if(xval) {
        xval.settext("正在处理中，请稍后...");
    }
    setTimeout(function() {
        var orderArry = new Array();
        $("div .active").each(function () {
            switch ($(this).attr("id")) {
                case "waitVerifyTab": // 待审核
                    $('input:checkbox[name=chkOrdera]:checked').each(function (i) {
                        orderArry.push($(this).attr("orderId"));
                    });
                    break;
                case "waitAssignTab": // 待分派
                    $('input:checkbox[name=chkOrderi]:checked').each(function (i) {
                        orderArry.push($(this).attr("orderId"));
                    });
                    break;
                case "shippingTab": // 发货中
                    break;
                case "shippedTab": // 已发货
                    break;
                case "completeTab": // 已完成
                    break;
                case "cancelTab": // 已废弃
                    break;
                default:
                    break;
            }
        });

        $.ajax({
            type: "POST",
            url: "/order/batchUpdateLogisticsCompany.action?lgstId=" + id + "&lgstName=" + name+ "&lgstCode=" + code,
            // contentType : "application/json;charset=utf-8",
            // dataType : "json",
            data: {"orderId": orderArry.join(",")},
            //async: true,// 同步
            success: function (data) {
            	xval.remove();
                if (data.result == "success") {
                    // 父窗体归还本页的编辑对话框
                    window.top.window.returnCustomModalDialog();
                    if (data.msg) {
                        window.top.window.showModalAlert(data.msg);
                    } else {
                        window.top.window.showModalAlert("批量设置物流公司成功");
                    }
                    $("#btnReturn").click();
                } else {
                    window.top.window.showModalAlert(data.msg);
                    window.top.window.borrowCustomModalDialog($("#modalBatchLgst"));
                }
            },
            error: function (XMLHttpRequest, textStatus) {
            	xval.remove();
                if (XMLHttpRequest.status == 500) {
                    var result = eval("(" + XMLHttpRequest.responseText + ")");
                    alert(result.errorObject.errorText);
                }
            }
        });
    },0);
}



/**
 * 批量设置平台备注
 *
 * @returns
 */
function bachSetSalesRemark() {
    var orderArry = new Array();
    //
    var remark = "";
    var n = 0;

    var tempShopType = "";
    var nShopType = 0;

    $("div .active").each(function () {
        switch ($(this).attr("id")) {
            case "waitVerifyTab": // 待审核
                $('input:checkbox[name=chkOrdera]:checked').each(function (i) {
                    // if (n == 0) {
                    //     remark = $(this).attr("salesRemark");
                    // } else {
                    //     remark = "";
                    //     return false;
                    // }
                    n++;

                    tempShopType = $(this).attr("shopType");
                    if(tempShopType != "淘宝"){
                        nShopType = 1;
                    }
                });
                break;
            case "waitAssignTab": // 待分派
                $('input:checkbox[name=chkOrderi]:checked').each(function (i) {
                    // if (n == 0) {
                    //     remark = $(this).attr("salesRemark");
                    // } else {
                    //     remark = "";
                    //     return false;
                    // }
                    n++;

                    tempShopType = $(this).attr("shopType");
                    if(tempShopType != "淘宝"){
                        nShopType = 1;
                    }
                });
                break;
            case "shippingTab": // 发货中
                $('input:checkbox[name=chkOrderk]:checked').each(function (i) {
                    // if (n == 0) {
                    //     remark = $(this).attr("salesRemark");
                    // } else {
                    //     remark = "";
                    //     return false;
                    // }
                    n++;

                    tempShopType = $(this).attr("shopType");
                    if(tempShopType != "淘宝"){
                        nShopType = 1;
                    }
                });
                break;
            case "shippedTab": // 已发货
                $('input:checkbox[name=chkOrderr]:checked').each(function (i) {
                    // if (n == 0) {
                    //     remark = $(this).attr("salesRemark");
                    // } else {
                    //     remark = "";
                    //     return false;
                    // }
                    n++;

                    tempShopType = $(this).attr("shopType");
                    if(tempShopType != "淘宝"){
                        nShopType = 1;
                    }
                });
                break;
            case "completeTab": // 已完成
                break;
            case "cancelTab": // 已废弃
                break;
            default:
                break;
        }
    });

    if (n == 0) {
        window.top.window.showModalAlert("请选择要批量设置的数据");
        return;
    }

    /*if (nShopType == 1) {
        window.top.window.showModalAlert("所选订单中存在来源非淘宝订单,请重新选取");
        return;
    }*/

    $("#updateSalesRemark").val(remark);
    $("#tbFlagCode").val(0);
    var editDialog = window.top.window.borrowCustomModalDialog($("#modalBatchSalesRemark"));
    editDialog.modal({
        show: true,
        backdrop: 'static'
    });
}



/**
 * 批量修改 保存 平台备注
 */
$("#btnBatchSalesRemark").click(
    function () {
        var xval = window.top.window.getIndexBusyOverlay();
        if(xval) {
            xval.settext("正在处理中，请稍后...");
        }
        // // 父窗体归还本页的编辑对话框
        // window.top.window.returnCustomModalDialog();
        setTimeout(function() {
            var orderArry = new Array();
            $("div .active").each(function () {
                switch ($(this).attr("id")) {
                    case "waitVerifyTab": // 待审核
                        $('input:checkbox[name=chkOrdera]:checked').each(function (i) {
                            orderArry.push($(this).attr("orderId"));
                        });
                        break;
                    case "waitAssignTab": // 待分派
                        $('input:checkbox[name=chkOrderi]:checked').each(function (i) {
                            orderArry.push($(this).attr("orderId"));
                        });
                        break;
                    case "shippingTab": // 发货中
                        $('input:checkbox[name=chkOrderk]:checked').each(function (i) {
                            orderArry.push($(this).attr("orderId"));
                        });
                        break;
                    case "shippedTab": // 已发货
                        $('input:checkbox[name=chkOrderr]:checked').each(function (i) {
                            orderArry.push($(this).attr("orderId"));
                        });
                        break;
                    case "completeTab": // 已完成
                        break;
                    case "cancelTab": // 已废弃
                        break;
                    default:
                        break;
                }
            });

            var varData = {
                "orderId" : encodeURI(orderArry.join(",")),
                "salesRemark" : encodeURI(window.top.window.$("#updateSalesRemark").val()),
                "tbFlagCode" : encodeURI(window.top.window.$("#tbFlagCode").val())
            };

            $.ajax({
                type: "POST",
                url: "/order/batchUpdateOrderSalesRemark.action?formJson="+encodeURI(JSON.stringify(varData)),
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                data: JSON.stringify(varData),
                //async: true,// 同步
                success: function (data) {
                    xval.remove();
                    // 父窗体归还本页的编辑对话框
                    window.top.window.returnCustomModalDialog();
                    if (data.result == "success") {
                        $('#modalBatchSalesRemark').find("#btnBatchSalesRemarkCancel").click();
                        window.top.window.showModalAlertPretty("批量执行完成：<br/>" + data.msg);
                        refresh();
                    } else {
                        window.top.window.showModalAlert(data.msg);
                        window.top.window.borrowCustomModalDialog($("#modalBatchSalesRemark"));
                    }
                },
                error: function (XMLHttpRequest, textStatus) {
                	xval.remove();
                    if (XMLHttpRequest.status == 500) {
                        var result = eval("(" + XMLHttpRequest.responseText + ")");
                        alert(result.errorObject.errorText);
                    }
                }
            });
        });
    });

//----------------------------------------------------------------------------------------------------------------
/**
 * 手动下载
 * 
 * @returns
 */
function downLoadTrade() {
    $("#downLoadForm")[0].reset();
    if ($("#optionsRadios1").attr("checked")=="checked"){
        $("#ecTradeCode").attr('readonly',false);
        $("#buyerNickDownload").attr('readonly',true);
        $("#optionsDiv1").html("<span class='require'>*</span>");
        $("#optionsDiv2").html("");
    } else {
        $("#ecTradeCode").attr('readonly',true);
        $("#buyerNickDownload").attr('readonly',false);
        $("#optionsDiv2").html("<span class='require'>*</span>");
        $("#optionsDiv1").html("");
    }    

    //设置店铺下拉列表
    $.ajax({
        type : "GET",
        url : "/shop/unpagedShopList.action?prjId=" + window.top.window.$("#projectSwitch").val(),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false,// 同步
        success : function(data) {
            if (data.result == "success") {
                $("#shopIdDownLoad option").remove();
                $("#shopIdDownLoad").append("<option value=''>请选择</option>");
                $.each(data.data, function(n, value) {
                    $('#shopIdDownLoad').append(
                            "<option value='" + value.shopId + "' shopType = '" + value.shopType + "'>" + value.shopName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
    
    
    var editDialog = window.top.window.borrowCustomModalDialog($("#modalDownLoad"));
    editDialog.modal({
        show : true,
        backdrop : 'static'
    });
}

/**
 * 主画面的列表刷新
 * 
 * @returns
 */
function refresh() {
    $('#quickSearch').val("");
    quickSearch = "";
    $("#advSearchReset").click();
    searchCondition = {};
    if (!$("#advSearchPanel").is(":hidden")){
        $("#btnAdvSearch").click();   
    } 
    $("div .active").each(function() {
        switch ($(this).attr("id")) {
        case "waitVerifyTab": // 待审核
            waitVerify.draw();
            break;
        case "waitAssignTab": // 待分派
            waitAssign.draw();
            break;
        case "shippingTab": // 发货中
            shipping.draw();
            break;
        case "shippedTab": // 已发货
            shipped.draw();
            break;
        case "completeTab": // 已完成
            complete.draw();
            break;
        case "cancelTab": // 已废弃
            cancel.draw();
            break;
        default:
            break;
        }
    });
    getCounts();
}

function setCitySelectNew() {
    // 市 初期化
    $.ajax({
        type : "GET",
        url : "/area/getCityList.action?provId=" + $("#provNameNew").val(),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false,// 同步
        success : function(data) {
            if (data.result == "success") {
                $("#cityNameNew option").remove();
                $("#cityNameNew").append("<option value=''>请选择</option>");
                $("#distNameNew option").remove();
                $("#distNameNew").append("<option value=''>请选择</option>");
                $.each(data.data, function(n, value) {
                    $('#cityNameNew').append("<option value='" + value.areaCode + "'>" + value.areaName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}

function setDistSelectNew() {
    // 区 初期化
    $.ajax({
        type : "GET",
        url : "/area/getDistList.action?cityId=" + $("#cityNameNew").val(),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false,// 同步
        success : function(data) {
            if (data.result == "success") {
                $("#distNameNew option").remove();
                $("#distNameNew").append("<option value=''>请选择</option>");
                $.each(data.data, function(n, value) {
                    $('#distNameNew').append("<option value='" + value.areaCode + "'>" + value.areaName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}

function setCitySelect() {
    // 市 初期化
    $.ajax({
        type : "GET",
        url : "/area/getCityList.action?provId=" + $("#provNameAssign").val(),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false,// 同步
        success : function(data) {
            if (data.result == "success") {
                $("#cityNameAssign option").remove();
                $("#cityNameAssign").append("<option value=''>请选择</option>");
                $("#distNameAssign option").remove();
                $("#distNameAssign").append("<option value=''>请选择</option>");
                $.each(data.data, function(n, value) {
                    $('#cityNameAssign').append("<option value='" + value.areaCode + "'>" + value.areaName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}

function setDistSelect() {
    // 区 初期化
    $.ajax({
        type : "GET",
        url : "/area/getDistList.action?cityId=" + $("#cityNameAssign").val(),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false,// 同步
        success : function(data) {
            if (data.result == "success") {
                $("#distNameAssign option").remove();
                $("#distNameAssign").append("<option value=''>请选择</option>");
                $.each(data.data, function(n, value) {
                    $('#distNameAssign').append("<option value='" + value.areaCode + "'>" + value.areaName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}

/**
 * 手动添加系统退款单
 * 
 * @param orderId
 *            订单ID
 * @param BtnObject
 *            列表上的按钮对象
 * @returns
 */
function addSysRefund(orderId, btnObject) {
    $.ajax({
        type: "GET",
        url: "/sysRefundManager/getSysRefundListByOrderId.action",
        contentType: "application/json;charset=utf-8",
        data: {
            "orderId": orderId
        },
        dataType: "json",
        async: false,
        success: function (data) {
            if (data.result == "success") {
                window.top.window.showModalConfirm("该订单已创建退款单，是否再次创建？", function() {
                    exeAddSysRefund(orderId, btnObject);
                });
            } else {
                exeAddSysRefund(orderId, btnObject);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                window.top.window.showScoMessage('error', result.errorObject.errorText);
            }
        }
    });
}
function exeAddSysRefund(orderId, btnObject) {
    
    var _orderId = orderId;
    // 如果订单为空，则从列表上取订单ID；如果取到的订单ID仍然为空，则提示“订单ID获取失败”
    if (!_orderId) {
        window.top.window.showScoMessage('error', "未取得订单信息，请联系管理员");
    } else {
        var iframeSrc = "/views/aftersale/sysrefund/sysRefundEdit.html?sysOrderId=" + _orderId;
        $("#ifmSysRefundDetail").attr("src", iframeSrc);
        // 新增的界面样例
        $("#btnSaveSysRefund").unbind("click").bind("click", function() {
            // 调用子页面的保存方法
            window.top.frames["ifmSysRefundDetail"].window.sysRefundEdit.saveSysRefund(window.top.frames["ifmSysRefundDetail"].contentWindow);
        });
        var sysRefundDetailDialog = window.top.window.borrowCustomModalDialog($("#modalSysRefundDetail"));
        sysRefundDetailDialog.on('hide.bs.modal', function() {
            // 父窗体归还本页的编辑对话框
            window.top.window.returnCustomModalDialog();
            refresh();
        });
        sysRefundDetailDialog.modal({
            show : true,
            backdrop : 'static'
        });

    }
}

/**
 * 手动新增系统退货单
 *
 * @param orderId
 *            订单ID
 * @param BtnObject
 *            列表上的按钮对象
 * @returns
 */
function addSysReturn(orderId, btnObject) {
    $.ajax({
        type: "GET",
        url: "/sysReturnManager/getSysReturnByOrderId.action",
        contentType: "application/json;charset=utf-8",
        data: {
            "orderId": orderId
        },
        dataType: "json",
        async: false,
        success: function (data) {
            if (data.result == "success") {
                window.top.window.showModalConfirm("该订单已创建退货单，是否再次创建？", function() {
                    exeAddSysReturn(orderId, btnObject);
                });
            } else {
                exeAddSysReturn(orderId, btnObject);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                window.top.window.showScoMessage('error', result.errorObject.errorText);
            }
        }
    });
}
function exeAddSysReturn(orderId, btnObject) {
    var _orderId = orderId;
    // 如果订单为空，则从列表上取订单ID；如果取到的订单ID仍然为空，则提示“订单ID获取失败”
    if (!_orderId) {
        window.top.window.showScoMessage('error', "未取得订单信息，请联系管理员");
    } else {
        var iframeSrc = "./views/aftersale/sysreturn/sysReturnEdit.html?sysOrderId=" + _orderId;
        $("#ifmSysReturnDetail").attr("src", iframeSrc);
        // 新增的界面样例
        $("#btnSaveSysReturn").unbind("click").bind("click", function() {
            // 调用子页面的保存方法
            window.top.frames["ifmSysReturnDetail"].window.sysReturnEdit.saveSysReturn(window.top.frames["ifmSysReturnDetail"].contentWindow);
        });
        var sysReturnDetailDialog = window.top.window.borrowCustomModalDialog($("#modalSysReturnDetail"));
        sysReturnDetailDialog.on('hide.bs.modal', function() {
            // 父窗体归还本页的编辑对话框
            window.top.window.returnCustomModalDialog();
            refresh();
        });
        sysReturnDetailDialog.modal({
            show : true,
            backdrop : 'static'
        });

    }
}

/**
 * 手动添加系统补发单
 * 
 * @param orderId
 *            订单ID
 * @param BtnObject
 *            列表上的按钮对象
 * @returns
 */
function addResend(orderId, btnObject){
    $.ajax({
        type: "GET",
        url: "/afterSaleResend/getResendByOrderId.action",
        contentType: "application/json;charset=utf-8",
        data: {
            "orderId": orderId
        },
        dataType: "json",
        async: false,
        success: function (data) {
            if (data.result == "success") {
                window.top.window.showModalConfirm("该订单已创建补发单，是否再次创建？", function() {
                    exeAddResend(orderId, btnObject);
                });
            } else {
                exeAddResend(orderId, btnObject);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                window.top.window.showScoMessage('error', result.errorObject.errorText);
            }
        }
    });
}
function exeAddResend(orderId, btnObject){
	var _orderId = orderId;
    // 如果订单为空，则从列表上取订单ID；如果取到的订单ID仍然为空，则提示“订单ID获取失败”
    if (!_orderId) {
        window.top.window.showScoMessage('error', "未取得订单信息，请联系管理员");
    } else {
    	var iframeSrc = "./views/aftersale/resend/addAfterSaleResend.html?resOrderId="+orderId;
        $("#ifmResendDetail").attr("src", iframeSrc);
        // 新增的界面样例
        $("#btnSaveResend").unbind("click").bind("click", function() {
            // 调用子页面的保存方法
        	window.top.frames["ifmResendDetail"].window.saveResend(window.top.frames["ifmResendDetail"].contentWindow);
        });
        var sysResendDetailDialog = window.top.window.borrowCustomModalDialog($("#modalResendDetail"));
        sysResendDetailDialog.on('hide.bs.modal', function() {
            // 父窗体归还本页的编辑对话框
            window.top.window.returnCustomModalDialog();
            refresh();
        });
        sysResendDetailDialog.modal({
            show : true,
            backdrop : 'static'
        });

    }
}

/**
 * 手动添加售后事件
 * @param orderId
 * @param btnObject
 * @returns
 */
function addEvent(orderId,orderCode, btnObject){
	$('#hidOrderCodeEvent').val(orderCode);
	$('#hidTradeCodeEvent').val('');
	$('#hidBuyerNickEvent').val('');
	$('#hidOrderIdEvent').val('');
    var _orderId = orderId;
  // 如果订单为空，则从列表上取订单ID；如果取到的订单ID仍然为空，则提示“订单ID获取失败”
  if (!_orderId) {
      window.top.window.showScoMessage('error', "未取得订单信息，请联系管理员");
  } else {
	//
	$.ajax({
        type:"GET",
        url:"/afterSale/getEventListByOrderId.action",
        data:{
        	"orderId":orderId
        },
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        async: false, // 同步
        success:function(data) {
        	console.log(data);
            if(data.result == "success"){
            	if(data.data.length > 0){
            		window.top.window.showModalConfirm("该订单下已经含有未处理完成的售后事件，是否继续新建。", function() {
            			addEventConfirm(orderId);
            		});
            	}else{
            		addEventConfirm(orderId);
            	}
            	
            }else{
            	 window.top.window.showModalAlert(data.msg);
            }
            
        },
        error:function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
        });
  }
	

//    // 如果订单为空，则从列表上取订单ID；如果取到的订单ID仍然为空，则提示“订单ID获取失败”
//    if (!_orderId) {
//        window.top.window.showScoMessage('error', "未取得订单信息，请联系管理员");
//    } else {

//
//    }
}
function addEventConfirm(orderId){
  var iframeSrc = "./views/aftersale/event/addAfterSaleEvent.html?resOrderId="+orderId;
  $("#ifmEventDetail").attr("src", iframeSrc);
  // 新增的界面样例
  $("#btnSaveEvent").unbind("click").bind("click", function() {
      // 调用子页面的保存方法
      window.top.frames["ifmEventDetail"].window.saveEvent(window.top.frames["ifmEventDetail"].contentWindow);
  });
  var sysEventDetailDialog = window.top.window.borrowCustomModalDialog($("#modalEventDetail"));
  sysEventDetailDialog.on('hide.bs.modal', function() {
      // 父窗体归还本页的编辑对话框
      window.top.window.returnCustomModalDialog();
      refresh();
  });
  sysEventDetailDialog.modal({
      show : true,
      backdrop : 'static'
  });
}

/**
 * 手动添加售后事件中查找订单方法
 * @param orderId
 * @param btnObject
 * @returns
 */
function modelShow() {
	window.top.window.returnCustomModalDialog();
	var btnType = "check";
	var iframeSrc2 = "./views/aftersale/event/addAfterSaleEventOrder.html?btnType=" + btnType;
	$("#ifmEventAddOrderDetail").attr("src", iframeSrc2);
	// $("#btnRuleDetailSave").unbind("click").bind("click", function() {
	// // 调用子页面的保存方法
	// window.top.frames["ifmEventAddOrderDetail"].window.saveEvent(window.top.frames["ifmEventAddOrderDetail"].contentWindow);
	// });
	var addEventOrderDialog = window.top.window.borrowCustomModalDialog($("#eventCheckWindow"));

	addEventOrderDialog.modal({
	    show : true,
	    backdrop : 'static'
	});
	addEventOrderDialog.on('hide.bs.modal', function() {
		// 父窗体归还本页的编辑对话框
		window.top.window.returnCustomModalDialog();
	});

}
//关闭查询页
$('#eventCheckWindow').on('hidden.bs.modal', function() {
	window.top.window.returnCustomModalDialog();
	window.top.window.borrowCustomModalDialog($("#modalEventDetail"));
});

// 关闭查询页
$('#eventCheckWindow').on('hide.bs.modal', function() {
	window.top.window.returnCustomModalDialog();
	window.top.window.borrowCustomModalDialog($("#modalEventDetail"));
});
//阻止事件冒泡函数
function stopBubble(e)
{
    if (e && e.stopPropagation)
        e.stopPropagation()
    else
        window.event.cancelBubble=true
}

var addItemTable = null;
/**
 * 查询goodsSku
 * 
 * @returns
 */
function doQuery(selectType) {
//    var goodsCode = window.top.window.$('#skuGoodsCode').val();
//    var goodsName = window.top.window.$('#skuGoodsName').val();
//    var skuCode = window.top.window.$('#skuSkuCode').val();
//    var skuName = window.top.window.$('#skuSkuName').val();
//    var isGift = window.top.window.$('#isGift').val();
//    if (goodsCode == "" && goodsName == "" && skuCode == "" && skuName == "") {
//        window.top.window.showModalAlert("请选择一个检索条件");
//        return;
//    }
    
    var advData = {
            "goodsCode" : encodeURI(window.top.window.$('#skuGoodsCode').val()),
            "goodsName" : encodeURI(window.top.window.$('#skuGoodsName').val()),
            "skuCode" : encodeURI(window.top.window.$('#skuSkuCode').val()),
            "skuName" : encodeURI(window.top.window.$('#skuSkuName').val()),
            "isGift": encodeURI(window.top.window.$('#isGift').val())
            ,"isVirt": encodeURI(window.top.window.$('#isVirt').val()||"")
        };
    

    addItemTable = window.top.window.$('#addItemTable').DataTable({
        "bPaginate": false,
        "bAutoWidth": true,
        "processing": true,
        "serverSide": true,
        "dom": '<"bottom"rtfli>',
        "searching": false,
        "deferRender": true,
        "info": false,
        "destroy":true,
//        "fnDrawCallback": function (oSettings) {
//            $("#chkAllItem").removeClass("sorting_asc");
//        },
        "ajax": {
            "url" : "/stockIn/getPrjSkuListForOrder4ModifySku.action?formJson="+encodeURI(JSON.stringify(advData)),
        },
        "tableTools": {
            "sRowSelect": "bootstrap"
        },
        "columns": [{
            "data": selectType
        }, {
            "data": "goodsCode"
        }, {
            "data": "goodsName"
        }, {
            "data": "skuCode"
        }, {
            "data": "skuName"
        }
        ],
        "columnDefs" : [ {
            "orderable" : false,
            "targets" : [ 0 ]
        } ],
        "order" : [ [ 2, "asc" ]]
    });
//    
//    $('#addNotBillItemTable').dataTable().fnClearTable();
//    $.ajax({
//        type : "POST",
//        url : "/stockIn/getPrjSkuList.action?formJson="+JSON.stringify(advData),
////        data : JSON.stringify(advData),
//        contentType : "application/json;charset=utf-8",
//        dataType : "json",
//        ordering: false,
//        async : true,// 同步
//        success : function(data) {
//            if (data.result == "success") {
//                $.each(data.data, function (n, value) {
//                    var ob = new Object();
//                    var checkbox = value.shipedQty=='0'?'':'<input name="chkPrjSku" prjSkuId="'+value.prjSkuId+'" type=\"checkbox\" />';
//                    var operation = value.shipedQty=='0'?'':'<a href="javascript:;" class="edit" prjSkuId="'+value.prjSkuId+' rowIndex ="'+n+'">编辑</a>'; //&nbsp;<a href="javascript:;" class="delete" orderSkuId="'+value.orderSkuId+' rowIndex ="'+n+'">删除</a>
//                    if (billData[value.skuCode]){
//                        addNotBillItemTable.fnAddData([
//                            '',
//                            value.goodsCode,
//                            value.goodsName,
//                            value.skuCode,
//                            value.skuName,
//                            '0',
//                            ''
//                        ]);
//                    } else {
//                        addNotBillItemTable.fnAddData([
//                            checkbox,
//                            value.goodsCode,
//                            value.goodsName,
//                            value.skuCode,
//                            value.skuName,
//                            '0',
//                            operation
//                        ]);
//                    }
//                    
//                    ob.skuId = value.skuId;
//                    ob.skuCode = value.skuCode;
//                    ob.skuName = value.skuName;
//                    ob.goodsId = value.goodsId;
//                    ob.goodsCode = value.goodsCode;
//                    ob.goodsName = value.goodsName;
//                    ob.qty = value.qty;
//                    ob.isGifts = 'n';
//                    
//                    mapNotBill["非单据:否:"+value.skuCode] = ob;
//                });
//            } else {
//                window.top.window.showModalAlert(data.msg);
//            }
//        },
//        error : function(XMLHttpRequest, textStatus) {
//            if (XMLHttpRequest.status == 500) {
//                var result = eval("(" + XMLHttpRequest.responseText + ")");
//                alert(result.errorObject.errorText);
//            }
//        }
//    });
}

/**
 * 导入
 */
function importOrder(){
	file = $("#upload-file");
    file.after(file.clone().val(""));
    file.remove()
    $("#adjustId").val("");
    mapAdjustSku={};
    skuIdex=0;
//    $("#newAdjustPageTitle").html("新增调整单");
//    // 构建第三方仓库下拉列表
//    $.ajax({
//        type: "GET",
//        url : "/stock/getExtStor.action",
//        contentType: "application/json;charset=utf-8",
//        dataType: "json",
//        async: false,
//        success: function (data) {
//            if (data.result == "success") {
//                $("#storIdNew option").remove();
//                $("#storIdNew").append("<option storCode='' value=''>请选择</option>");
//                $.each(data.data, function (n, value) {
//                    $('#storIdNew').append("<option storCode='" + value.storCode + "' value='" + value.storId +"'>" + value.storName + "</option>");
//                });
//                refresh();
//            } else {
//                window.top.window.showModalAlert(data.msg);
//            }
//        },
//        error: function (XMLHttpRequest, textStatus) {
//            if (XMLHttpRequest.status == 500) {
//                var result = eval("(" + XMLHttpRequest.responseText + ")");
//                alert(result.errorObject.errorText);
//            }
//        }
//    });

    //备注清空
    $("#remarkNew").val("");
    $("#clearAll").show();
    $('#adjustTableUpdate').dataTable().fnClearTable();

    // 规格新规列表
    if (adjustTableUpdate == null) {
        adjustTableUpdate = $('#adjustTableUpdate').dataTable({
            "bPaginate" : false,
            "bAutoWidth" : true,
            "bSort" : false,
            "searching" : false,
            "bDeferRender" : true,
            "bDestroy" : true,
            "dom" : '<"bottom"rtflp>',
            "fnInitComplete": function (oSettings) {
                $("#thShopAccount").removeClass("sorting_asc");
            },
            "fnDrawCallback": function (oSettings) {
            	window.top.window.$("#thShopAccount").removeClass("sorting_asc");
            }
        });
    }
    $("#upload-file").unbind("change").bind("change", importf);
    var editDialog = window.top.window.borrowCustomModalDialog($("#newAdjustPage"));
    editDialog.modal({
        show : true,
        backdrop : 'static'
    });
}

$('#newAdjustPage').on('hide.bs.modal', function() {
    // 父窗体归还本页的编辑对话框
    window.top.window.returnCustomModalDialog();
});

//下载模板
$('#downloadExcel').click(function() {
    window.location.href="/views/order/orderTemplate.xls";
});

$("#clearAll").click(function(){
    window.top.window.$("#adjustTableUpdate tbody tr").each(function() {
        mapAdjustSku={};
        adjustTableUpdate.fnDeleteRow($(this));
    });
//    nEditing = null;
});

// 设置规则详情对话框关闭事件发生
$('#modalDownFile').on('hide.bs.modal', function () {
    // 父窗体归还本页的编辑对话框
    window.top.window.returnCustomModalDialog();
    window.top.window.borrowCustomModalDialog($("#newAdjustPage"));

})

$("#modalDownFile").on('show.bs.modal',function(){
    file = $("#upload-file");
    file.after(file.clone().val(""));
    file.remove()
    $("#upload-file").unbind("change").bind("change", importf);
});
